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
| global PrefFile, MesPref
property NomPref : "com.thy06" -- le nom de ton fichier de préférence à changer selon ton besoin
set PrefFile to ((path to preferences folderfromuser domain) as string) & NomPref
-- lors du lancement, on vérifie si les préf existent et sinon, on les crée
tell application "Finder"
try
set ExistDeja to (PrefFile exists)
on error
set ExistDeja to false
end try
end tell
if ExistDeja then
LitPref()
else
CreationPref()
end if
-- ton code ici qui utilise les variables de MesPref
display dialog "Compteur=" & (monCompteur of MesPref) with title (montexte of MesPref)
set monCompteur of MesPref to (monCompteur of MesPref) + 1 -- incrémenter le compteur avant de le sauver
EcritPref() -- avant de quitter, on écrit les variables pour la prochaine fois
-- fin du programme
-- *************************
on CreationPref() -- routine pour initialiser les variables et créer le fichiers
-- mettre ici l'initialisation de tes variables MesPref. Par exemple :
set MesPref to {montexte:"ceci est un essai", monCompteur:1}
EcritPref()
end CreationPref
-- *************************
on EcritPref() -- routine d'enregistrement des variables
try
open for access (file PrefFile) with write permission
write MesPref as record to (file PrefFile) starting at 0
close access (file PrefFile)
on error
close access (file PrefFile)
end try
end EcritPref
-- *************************
on LitPref() -- routine de lecture des variables
set MesPref to (read (file PrefFile) as record)
end LitPref |
Partager