J’essaie sous OSX 10.12.6 de réutiliser un script ancien pour normaliser les noms des contacts du carnet d’adresses, (script « optimisé" il y a fort longtemps grâce à l’aide avisée d'Yvan Koenig), et le script ne compile plus:
le problème semble lié à la ligne: tell application "Contacts" to set l to (name of every group)
qui retourne : « nom de classe prévu mais identificateur trouvé(s)
J’ai regardé le dictionnaire de l’application sans trouver d’explication, il existe bine un « group » doté d’un nom…
Quelle est le problème et surtout la solution ?
Merci
—DEBUT SCRIPT
(*************************************************************************************************)
(* Script de conversion prénoms du carnet d'adressses en caractères minuscules, le premier caractère restant ou devenant majuscule.
* Les tirets dans les prénoms composés ne sont pas pris en compte et sont éliminés.
*Version: 0.9.3
* Compatibilité: Mac OS X. Le carnet d'adresses Apple doit être présent
*
* Auteur: Y Petronin avec code emprunté à Apple
*
* Fichier:
* Fichiers/Dossiers annexes:
* Libs:
* Osaxen:
* Outils Unix: non
* Apps:
*
* Description:
*
* * Utilisation: ...Lancer le script... *
* Historique: Aménagements variés:
*
* 0.9.8
* 2009-01-02 Version alpha *
* 2009-01-06 Added routine to handle composed names (containing an hyphen)
* 2009-01-07 Moved routine to handle composed names outside of main
* 2009-01-09 Added several routines to allow user to select groups in address book
*2013-05-19 Added option for lower or to upper characters for names
*2013-05-27 Major simplification with use of Python
*2019-04-28 Correction or routien filtering the german character sz
*)
(* Product properties *)
property pMyName : "Conversion caractères prénoms carnet d'adresses" (* default name *)
property version : "0.9.3"
--User properties
property PGroupName : missing value (*Nom du groupe du carnet d'adresses à traiter*)
property pThePerson : missing value (*Nom du contact du carnet d'adresses*)
property pTheFormat : missing value (*Format des noms propres*)
property p2Contacts : missing value
-----------------------------------------------------------------------------------------------------------------------------
on init()
set pTheFormat to my GetFormat()
set PGroupName to my GetGroups()
end init
---------------------------------------------------------------------------------------------------------------------
on run
main()
end run
----------------------------------------------------------------------------------------------------------------------
on main()
init()
my UpdateNames(pThePerson, PGroupName, pTheFormat)
end main
--------------------------------------
on GetGroups()
tell application "Contacts" to set l to (name of every group)
if l is in {"", missing value} then
return missing value
else
set L1 to {"Tous"} & l -- items of l
tell application (path to frontmost application as text) -- POUR METTRE LE CAIALOGUE AU PREMIER PLAN
choose from list L1 with prompt " Ce script formate prénoms et noms des contacts du cahier d'adresses." & return & "Il est recommandé de sauvegarder au préalable votre carnet d'adresses." & return & "Veuillez choisir ci dessous un ou plusieurs groupes de contacts à traiter ou tous les contacts: " cancel button name "ANNULER" OK button name "OK" without multiple selections allowed and empty selection allowed
end tell
if the result is false then
delay 0.5
error number -128
else
return the result as text
end if
end if
end GetGroups
on GetFormat()
set L1 to {"DUPONT", "Durand"}
set dlg to choose from list L1 with prompt "Veuillez choisir le format des noms de famille" cancel button name "ANNULER" OK button name "OK" without multiple selections allowed and empty selection allowed
set r to the result
if the r as text is "Durand" then
return "title"
end if
if the r as text is "DUPONT" then
return "upper"
end if
if r is false then
error number -128
end if
end GetFormat
on UpdateNames(pThePerson, PGroupName, pTheFormat)
if PGroupName is not in {missing value, "Tous"} then
set g to "Cette opération peut prendre plusieurs minutes !"
my dlgAlert(g)
tell application "Contacts"
repeat with pThePerson in people of group PGroupName
set TheNom to the (first name of the pThePerson) as text
tell pThePerson to set first name to my FormatName(TheNom, "title") as string
set FamilyName to the (last name of the pThePerson) as text
tell pThePerson to set its last name to my FormatName(FamilyName, pTheFormat)
save
end repeat
end tell
else
set g to "Tous les contacts seront traités! Cette opération peut prendre plusieurs minutes !"
my dlgAlert(g)
tell application "Contacts"
repeat with pThePerson in people
set TheNom to the (first name of the pThePerson) as text
tell pThePerson to set first name to my FormatName(TheNom, "title") as string
set FamilyName to the last name of the pThePerson as text
tell pThePerson to set its last name to my FormatName(FamilyName, pTheFormat)
save
end repeat
end tell
end if
end UpdateNames
on dlgAlert(g)
activate
set bs to {"ANNULER", "CONTINUER"}
display dialog g buttons bs default button 2 with icon 1 giving up after 8
set {b, u} to {button returned, gave up} of result
if u then set b to bs's item 1
if b is bs's item 1 then error number -128 (* ¡localization! *)
end dlgAlert
on FormatName(TheNom, pTheFormat) (*Retourne le texte en ajoutant une majuscule initiale à chaque mot du texte et convertit les autres caractères en minuscules le cas échéant*)
try
if TheNom is in {"", "msng", "missing value"} then
return ""
else
set NewName to my changecase(TheNom, pTheFormat)
--if pTheFormat is "upper" then
-- set NewName to my ChangeAccentedCapitals(NewName)
--end if
end if
return NewName
on error
return ""
end try
end FormatName
on changecase(txt, mode) --Le second argument peut être: "upper", "lower", "title", "capitalize"
set oTIDs to AppleScript's text item delimiters
try
set toReplace to {"ß", "É", "È", "Ë", "Ê", "Ç"}
set replaceBy to {"SS", "E", "E", "E", "E", "C"}
repeat with i from 1 to count items of toReplace
set beforeChar to item i of toReplace
if mode is "upper" and txt contains beforeChar then
-- log "before process" & space & txt
set oTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to beforeChar
set l to text items of txt
set AppleScript's text item delimiters to item i of replaceBy
set txt to "" & l
set AppleScript's text item delimiters to oTIDs
--log "after process" & space & txt
end if
end repeat
on error
set oTIDs to AppleScript's text item delimiters
end try
set python_cmd to "import sys; print sys.argv[1].decode('utf8')." & mode & "().encode('utf8')"
return do shell script "/usr/bin/python -c " & quoted form of python_cmd & " " & quoted form of txt
end changecase
—FIN SCRIPT
_______________________________________________
Applescript_fr mailing list
Applescript_fr@???
http://listes.patpro.net/mailman/listinfo/applescript_fr