Hi again guys,
I tried searching on this for a while but couldn’t find anyone doing the same. What I need to do is take a relative posix path and have it return a full mac path. The situation is this app needs to check the existence of certain .plist files in a users home library as well as system library. Since everyone’s HD and home folder has a different name, i wanted to use relative paths (~/Library/Preferences/). What I have so far is this:
set posixPath to “~/Library/Preferences/”
set macPath to POSIX file posixPath as string
display dialog macPath
and that of course returns macPath as such :~:Library:Preferences: which will not work. How can it get it to return the full mac path from a relative POSIX path. Or maybe is there a way to do a relative mac path in applescript that I have no idea about? Thanks.
There are a few ways to check whether a prefs file exists. You can check it my hardcoding the path, by using a “path to:” property, or by using the defaults system via a shell script. The code below uses a simple path to and doesn’t require any hardcoding of the pref folder paths. Also, it by default uses the mac-style paths so no posix coercions are necessary. As it is, it checks both the user and system preferences for the existence of a plist file. I used an apple plist that was in both so I could test the code, but you could obviously replace that with your own plist.
(* For dialog output only *)
set theMessage to "Found: "
set tmpDelim to ""
(* The plist you're looking for *)
set queryDomain to "com.apple.BezelServices.plist"
(* Check User Domain *)
try
set userDomain to list folder (path to preferences folder from user domain)
if userDomain contains queryDomain then
set theMessage to theMessage & "User Domain"
set tmpDelim to ", "
end if
end try
(* Check System Domain *)
try
set systemDomain to list folder (path to preferences folder from local domain)
if systemDomain contains queryDomain then
set theMessage to theMessage & tmpDelim & "System Domain"
end if
end try
if (theMessage is "Found: ") then
set theMessage to "Found: Nowhere"
end if
display dialog theMessage