Q: How do I make a variable path in AppleScript?
I'm mass distributing an application, and for the next update I want to add customization. My application currently make a folder in the "Documents" folder. The folder is called "MCL_CONFIG". What I need to do is make a unicode text file in "MCL_CONFIG". Since it's going to be used on many different computers the path to where I'm making the new file has to change depending on the user. How can I make a variable path to a non-directory? Here's the section of my code with the problem:
tell application "Finder"
if folder MCLConfig exists then
else
display dialog "Welcome to Mc Launcher! You will only recieve this message once, unless you delete the MCL_CONFIG folder." buttons {"Ok"} default button 1
make new folder at New_User with properties {name:"MCL_CONFIG"}
end if
end tell
It's not shown but I set the variable MCLCONFIG to (path to documents folder from user domain) & "MCL_CONFIG" as text.
As a side note how do I make the code look like it does in applescript, here?
Posted on Mar 13, 2013 1:53 PM
You can do something like:
set supportFolder to ((path to application support from user domain) as text)
set appName to "My Spiffy App"
set subFolder to "MCL_CONFIG"
tell application "Finder" -- add application support folders if needed
if not (exists folder (supportFolder & appName)) then
make new folder at folder supportFolder with properties {name:appName}
make new folder at result with properties {name:subFolder}
end if
end tell
Edit: it is recommended that the folder in Application Support be named with your application's bundle identifier, but most just use the application name.
Posted on Mar 13, 2013 9:53 PM