Reputation: 37238
I am using privelaged javascript which has access to python like ctypes and the whole mac api.
Programmatically I'm trying to create an applescript file and set its icon.
I'm trying follow this tutorial here on how to make profile shortcuts on macs: http://weblogs.mozillazine.org/asa/archives/2008/08/shortcut_to_lau.html
Is this as simple as creating a text file and populating it with some text?
I dont have a mac, just coding for my mac users.
Upvotes: 1
Views: 661
Reputation: 19030
You'll want to use the command line tool osacompile to create a compiled applescript file. You can look at its man page to see all your options but it's rather simple. For example, suppose you wanted to write the following applescript code to a file...
tell application "Safari"
activate
end tell
You can do it with osacompile and using the "-e" option before each line of code. Note that I put single quotes around each line too.
set savePath to (path to desktop as text) & "test.scpt"
do shell script "osacompile -e 'tell application \"Safari\"' -e 'activate' -e 'end tell' -o " & quoted form of POSIX path of savePath
If you don't like the "-e" option, you could pipe the code text using echo...
set scriptText to "tell application \"Safari\"
activate
end tell"
set savePath to (path to desktop as text) & "test.scpt"
do shell script "echo " & quoted form of scriptText & " | osacompile -o " & quoted form of POSIX path of savePath
The saved file will have the default applescript icon. If you also want to change its icon you can use a command line tool I wrote called SetFileIcon. Find it here. There's directions on the page.
Upvotes: 4