Run a .scpt (AppleScript) from the terminal?

Is there a way to execute a saved AppleScript (.scpt) from the terminal?

I have tried *osascript /Users/path/to/script.scpt* and it says "execution error: No user interaction allowed. (-1713)"

No difference if I use sudo or not.

24" iMac - Core 2 Duo 2.16, Mac OS X (10.4.8), 2GB RAM • GeForce 7600 GT • 3G iPod 10GB

Posted on Sep 11, 2007 10:34 PM

Reply
7 replies

Sep 12, 2007 6:24 AM in response to zwei

The ' osascript' command is what would normally be used. I have noticed that some user interaction commands that work normally in AppleScript don't work through ' osascript'. For example, a naked 'display dialog "hello"' will work in AppleScript but an ' osascript -e 'display dialog "hello"'' from the shell won't.

If this is the problem and you are able to edit the code, putting the user interaction command inside a "tell" block for any application usually serves as a workaround. I don't know if there is something that can be modified in the shell to allow the unmodified commands to work though...

Sep 12, 2007 6:34 AM in response to biovizier

The only thing is I am not wanting to run a command via the terminal ..I want to launch a script that I have saved as a .scpt file. The reason I want to do it this way is because I have several properties in the script that I need saved from run to run. Is there not a way to have the system just run a specified script file?

Sep 12, 2007 7:33 AM in response to zwei

I only used the example of 'osascript' with the '-e' flag so that you would have a quick example you could test directly.The same problem applies with 'osascript' running a .scpt file. If it is possible, modify the code (if it contains naked user interaction commands - without seeing the code, it is impossible to tell). Otherwise, I suppose you could GUI script something but that would be ugly. Unless someone else knows what the specific issue is with user context or how to get around it...

Sep 12, 2007 2:09 PM in response to zwei

You may need to save the script as an app rather than as a compiled script.

The issue is that if your script includes any user interaction (e.g. the 'display dialog'), then it has to run in the GUI.

As a .scpt file, the script is technically a document, and that document needs an application, so just opening it normally will launch a script editor.

Conversely, saving it as an app will allow the app to run standalone, so you can just use the standard open command:

<pre class=command>open /Users/path/to/script.app</pre>

You'll still be able to open and edit the script with Script Editor, but the .app has the ability to stand on its own.

Sep 12, 2007 2:25 PM in response to Camelot

Yeah, I know I could get around this by saving it as an app. The thing is I am wanting to schedule this via Lingon (launchd) and have it run every 30 min. I really don't want to be annoyed with the app popping up in the dock every 30 min.

I don't think it has a dialog in it ...it definitely doesn't need one. I'm off work in 10 min, so I will post it when I get home.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Run a .scpt (AppleScript) from the terminal?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.