Folks,
I’m new to AS and I’m trying to script a check of a bunch of preference files in the local user folders. I’ve tried a number of pure applescript solutions but none seem to get access to the files as needed, so I’ve resorted to embedded shell scripting.
What I want to do is VERY simple:
if exists file 1.cfg in the folder Application in Application Support in Library in the user folder then return “true”
My problem is that I can’t seem to get the file paths right between AS and the shell syntax. Here’s what I’ve come up with so far:
set theFile to quoted form of (do shell script "echo $HOME/Library/Application Support/Application/1.cfg")
What is the most compact and convenient way to do this? I’ve scoured a number of AS forums without finding a good solution to this. Also, I’d like a script that is compatible back to 10.3 if possible.
Thank you,
O
Hi olindefelt,
I would suggest the following AppleScript code to solve your problem:
-- folder path to the user's application support folder
set appsuppfolderpath to (path to application support from user domain) as Unicode text
-- file path to the preferences file
set prefsfilepath to (appsuppfolderpath & "Application:1.cfg") as Unicode text
try
-- does the file exist?
set prefsfilealias to prefsfilepath as alias
-- yes, it does!
return true
on error
-- no, it doesn't
return false
end try
This also makes the do shell script command obsolete, your task can be accomplished by AppleScript alone.
HTH!
That is AMAZING! Thank you soo much for your help!!!
One thing: another file I’m looking for is in the folder Internet Plug-Ins in the Library in the user domain. Is there a way to get at that using the same method? It doesn’t seem to be as convenient.
O
set libPath to (path to library folder from user domain) as Unicode text
try
set pluginPath to (libPath & "Internet Plug-Ins") as alias
return true
on error
return false
end try
Hi olindefelt,
It’s just as easy as before
-- folder path to the user's internet plugins folder
set inetplugsfolderpath to path to internet plugins folder from user domain
set inetplugsfolderpath to inetplugsfolderpath as Unicode text
-- file path to the plugin file
set inetplugfilepath to (inetplugsfolderpath & "weirdpluginname.plugin") as Unicode text
try
-- does the plugin file exist?
set inetplugfilealias to inetplugfilepath as alias
-- yes, it does!
return true
on error
-- no, it doesn't
return false
end try
Here is a list with the special folders:
http://www.foodoo.sunreal.com.au/info/folders.html
Of course you can always use the following general approach. Just find out the path to to the library folder first and then add the rest of the required path:
-- folder path to the user's library folder
set libraryfolderpath to (path to library folder from user domain) as Unicode text
-- folder path to a certain folder inside the library folder
set specialfolderpath to (libraryfolderpath & "Weird Folder:") as Unicode text
-- file path of a weird file inside the certain folder :)
set specialfilepath to (specialfolderpath & "weirdfile.weird") as Unicode text
try
-- does the file exist?
set specialfilealias to specialfilepath as alias
-- yes, it does!
return true
on error
-- no, it doesn't
return false
end try
Happy Pathfinding!
Thank you guys! You are incredible.!