Re: Mysterious Preferences File Again
Re: Mysterious Preferences File Again
- Subject: Re: Mysterious Preferences File Again
- From: Luther Fuller <email@hidden>
- Date: Sun, 14 May 2006 13:29:42 -0500
I think I have a fix for my latest problem with preference files.
My script starts with this ...
on run
try
short name of (info for (path to frontmost application))
if the result = "Mail" then
...
At some point, the user may arrive at the handler ...
on getAbbreviations()
set prefsFile to my getPrefsFile()
tell application "System Events"
POSIX path of prefsFile
set abbrList to (value of property list item
"UsersAbbreviations" of property list file the result)
end tell
repeat
activate me
abbrList & {"+ (Add New)", "- (Delete)"}
tell me to choose from list the result with prompt ¬
"Select an abbreviation ..." cancel button name "None"
... and lots more stuff
The 'getPrefsFile' handler returns an alias to the prefs file (and
creates the prefs file if it doesn't exist). Apparently, putting
'getPrefsFile' and 'choose from list' in the same handler opens a
leak from 'choose from list' into the new prefs file. Or, perhaps
'choose folder' has already created a bogus prefs file without the
key value my script expects to read. If an uncorrupted prefs file
already exists, there appears to be no problem.
The fix is to make this change ...
on run
try
my getPrefsFile() --< added
short name of (info for (path to frontmost application))
if the result = "Mail" then
...
which creates the new prefs file before 'choose from list' or 'choose
from folder' gets anywhere near it.
I have not yet found a fix for the original problem where an unwanted
prefs file is created for applications that don't use a prefs file,
but do use 'choose ...'. If anyone has additional insight into this
problem, please let us know.
FWIW ...
on getPrefsFile()
tell application "Finder" to set selfRef to (path to me) as alias
tell application "System Events"
POSIX path of (file "Info.plist" of folder "Contents" of selfRef)
set prefsName to (value of property list item "CFBundleIdentifier"
of property list file the result)
end tell
set prefsName to (prefsName & ".plist") as text
(path to preferences from user domain) as text
tell application "Finder"
set prefsFolder to the result as alias
if not (exists file prefsName of prefsFolder) then
(file ("NewPrefsFile.plist") of folder "Resources" of folder
"Contents" of selfRef) as alias
duplicate the result to prefsFolder
set name of the result to prefsName
end if
try
set fullPath to (prefsFolder as text) & prefsName
set prefsFile to (fullPath as alias)
on error errText number errNr
"getPrefsFile Error = " & errNr & return & errText
display dialog the result
end try
end tell
return prefsFile
end getPrefsFile
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden