I try to check if a .plist file exists in user library folder. Following this, I try:
property file_path : quoted form of POSIX path of ("~/Library/Preferences/org.MyFile.plist")
tell application "Finder" to set optsFound to exists file_path
if optsFound then
display dialog file_path
else
beep
end if
Obviously file exist but I always get a beep
And how can I set the path of the plist file without set the userâs name?
Thanks.
One of the problems is â~/â will not get expanded in applescript
You could try this.
property library_folderPath : (path to preferences folder from user domain) as string
property file_ : "org.MyFile.plist"
property file_path : ""
try
set file_path to POSIX path of (library_folderPath & file_ as alias)
display dialog file_path
on error
beep
end try
You can lose some code by combining the first line and second,
property library_folderPath : (path to preferences folder from user domain) & "org.MyFile.plist" as string
property file_path : ""
try
set file_path to POSIX path of (library_folderPath as alias)
display dialog file_path
on error
beep
end try
but I think it is better for editing and reuse to keep
the file name separate
itâs strongly not recommended to assign a relative path to a property.
Once compiled the path is persisitent and the script is not protable.
You could check for an existing domain in the plist file with /usr/bin/defaults
property file_name : "org.MyFile"
property domain : "myDomain"
try
do shell script "/usr/bin/defaults read " & file_name & " " & domain
return true
on error
return false
end try
Your statement is correct but I think that path to userâs preferences folder is quite absolute than relative, isnât it?
Iâm trying to ASOCifing scripts of portable applications, hoping it worth. I know are not a scripts masterpiece, just done with great passion for ĂŻÂŁÂż. Thanks for all your help.
No, path to preferences folder is a relative path (alias [startup disk]:Users:[current user]:Library:Preferences:)
At compile time the property will be set to the path to the preference folder of the current user.
It wonât work in a different user account unless the script will be recompiled