I want to run some lines of applescript code from within my application. The standard way is to use the NSAppleScript class. However, because that code might take a few minutes to complete, I have to use a separate thread or the interface will stop. The big problem is, as it says here, the NSAppleScript class can ONLY be run on the main thread.
So, if I run the code on a separate thread, my app crashes; If I run it on the main thread, it stops. Any ideas?
Also, I considered using NSTask and the osascript command, but I saw somewhere (can’t find the link) that osascript doesn’t support user input such as dialog boxes and stuff. I’m not sure if that’s true, but if it is then osascript is not a solution.
So I ended up writing a helper for this, launched via NSTask. Here is the code, in case anyone’s interested:
For the launcher:
And the helper: