1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
| global Mes_pref, Pref_Application, Pref_Bibli-- met en global ces variables pour pouvoir les appeler à niveau
property Nom_Pref : "com.Perso.Appli" -- exemple de nom de préférences (URL inversée) possible en format PList!
property Mes_pref : {Interview:"ITW", Lives:"Live", Illus:"ILL", Ambiances:"AMB", Coupe:"PCTIW", Synchro:"SYNCRO", Favori:true, Mot_Cle:true, Marqueurs:true, Roles:true, Signe_Note:"*", Niveau:3}
-- initialisation des variables
set Pref_Application to ((path to me) as string) & "Contents:Resources:" & Nom_Pref
set Pref_Bibli to ((path to preferences folder) as string) & Nom_Pref
-- programme principal
Get_Pref() -- initialisation à lancer au début de l'application
set Lives of Mes_pref to "LIVE"
set R to display dialog "Voulez vous modifier les préférences" buttons {"Modifier", "Continuer"} default button "Continuer"
if (button returned of R) is "Modifier" then Modif_Pref() -- sous routine de changement des préférences
display dialog "fin du programme"
-- fin du prgramme principal
on Get_Pref() -- lit le fichier préférence à partir du fichier en bibliothèque, sinon, du paquet application, sinon à partir des valeur par défaut (et crée le fichier bibliothèque)
set A_Sauver to false
tell application "Finder"
if (exists (filePref_Bibli)) then -- lecture du fichier via Pref_Bibli
try
set Mes_pref to (read (file Pref_Bibli) as record)
on error
close access (filePref_Bibli)
end try
else if (exists (filePref_Application)) then -- lecture de Pref_Application et écriture vers Pref_Bibli
set Mes_pref to (read (filePref_Application) asrecord)
set A_Sauver to true
else
set A_Sauver to true-- 2criture des property par défaut
end if
end tell
if A_Sauver then Save_Pref() -- appel à une sub-routine en dehors du bloc tell "Finder"
end Get_Pref
on Save_Pref() -- enregistre le record Mes_Pref dans le fichier préférences
try
open for access (filePref_Bibli) with write permission
writeMes_prefasrecordto (filePref_Bibli) starting at 0
close access (filePref_Bibli)
on error
close access (filePref_Bibli)
end try
end Save_Pref
on Modif_Pref()
-- exemple de gestion des préférences (malgré les limitations d'interface AppleScript). Cette partie gagnera à être faite via XCode
-- choix des préférences : type de marqueurs ou abréviations ou signe et Niveau (un seul choix)
set Change_Fait to false
set M_Liste to {"Interview (" & Interview of Mes_pref & ")", "Lives (" & Lives of Mes_pref & ")", "Illustrations (" & Illus of Mes_pref & ")", "Ambiances (" & Ambiances of Mes_pref & ")", "Plan de coupes (" & Coupe of Mes_pref & ")", "Son Synchro (" & Synchro of Mes_pref & ")"}
set Saisie to choose from listM_Listewith prompt "Valeurs et codes à modifier" with multiple selections allowed
if Saisie is not false then
repeat with Choix in Saisie
if Choix contains "Interview" then
set Cur_Val to Interview of Mes_pref
set N_Val to display dialog "Changement d'abréviation pour les interviews" default answer Cur_Val buttons {"Enregistrer", "Adandonner"}
if (button returned of N_Val) is "Enregistrer" then
set Interview of Mes_pref to text returned of N_Val
set Change_Fait to not (Interview of Mes_pref is Cur_Val)
end if
end if
if Choix contains "Lives" then
set Cur_Val to Lives of Mes_pref
set N_Val to display dialog "Changement d'abréviation pour les Lives" default answer Cur_Val buttons {"Enregistrer", "Adandonner"}
if (button returned of N_Val) is "Enregistrer" then
set Lives of Mes_pref to text returned of N_Val
set Change_Fait to not (Lives of Mes_pref is Cur_Val)
end if
end if
if Choix contains "Illustrations" then
set Cur_Val to Illus of Mes_pref
set N_Val to display dialog "Changement d'abréviation pour les Illustrations" default answer Cur_Val buttons {"Enregistrer", "Adandonner"}
if (button returned of N_Val) is "Enregistrer" then
set Illus of Mes_pref to text returned of N_Val
set Change_Fait to not (Illus of Mes_pref is Cur_Val)
end if
end if
if Choix contains "Ambiances" then
set Cur_Val to Ambiances of Mes_pref
set N_Val to display dialog "Changement d'abréviation pour les ambiances" default answer Cur_Val buttons {"Enregistrer", "Adandonner"}
if (button returned of N_Val) is "Enregistrer" then
set Ambiances of Mes_pref to text returned of N_Val
set Change_Fait to not (Ambiances of Mes_pref is Cur_Val)
end if
end if
if Choix contains "Plan de coupes" then
set Cur_Val to Coupe of Mes_pref
set N_Val to display dialog "Changement d'abréviation pour les plans de coupe" default answer Cur_Val buttons {"Enregistrer", "Adandonner"}
if (button returned of N_Val) is "Enregistrer" then
set Coupe of Mes_pref to text returned of N_Val
set Change_Fait to not (Coupe of Mes_pref is Cur_Val)
end if
end if
if Choix contains "Son Synchro" then
set Cur_Val to Synchro of Mes_pref
set N_Val to display dialog "Changement d'abréviation pour les sons syncrho" default answer Cur_Val buttons {"Enregistrer", "Adandonner"}
if (button returned of N_Val) is "Enregistrer" then
set Synchro of Mes_pref to text returned of N_Val
set Change_Fait to not (Synchro of Mes_pref is Cur_Val)
end if
end if
end repeat -- sur chaque valeur d'abréviation à modifier
end if --si il faut changer les abréviations
-- selection des types de records (Favori, Mot-clé, Marqueurs et Roles)
set M_Liste to {"Favoris", "Mots-clé", "Marqueurs", "Roles"}
set Pre_Liste to {}
if Favori of Mes_pref then set Pre_Liste to Pre_Liste & {"Favoris"}
if Mot_Cle of Mes_pref then set Pre_Liste to Pre_Liste & {"Mots-clés"}
if Marqueurs of Mes_pref then set Pre_Liste to Pre_Liste & {"Marqueurs"}
if Roles of Mes_pref then set Pre_Liste to Pre_Liste & {"Roles"}
set Saisie to choose from listM_Listewith prompt "Types d'enregistrement à prendre en compte" default itemsPre_Liste with multiple selections allowed
if Saisie is not false then
set Favori of Mes_pref to (Saisie contains "Favori")
set Mot_Cle of Mes_pref to (Saisie contains "Mots-Clés")
set Marqueurs of Mes_pref to (Saisie contains "Marqueurs")
set Roles of Mes_pref to (Saisie contains "Roles")
set Change_Fait to true-- on pourrai ici vérifier quel attribut a été changé ou non !
end if --si il faut changer les types de records
if Change_Fait then Save_Pref()
end Modif_Pref |
Partager