1

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.

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for such a detailed step by step thing, Ill test this out and report back! :) For a total non mac usre you really got detailed thanks so much!
With your SetFileIcon script, say i set the image to /blah/blah.png does that image have to remain at that location? or can i delete it and the applescript will still retain the icon?
You can delete it. Good luck.
Wow awesome script man thank you!! Im trying to get onto a mac vm so i can test this and get firefox profiles launching per that tutorial :)
Thanks man it worked awesome except that it won't launch, it keeps giving "unidentified author" error :( stackoverflow.com/questions/25859379/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.