You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Syntax to run AppleScript in Automator

I'm running Catalina on a Late 2012 Mac mini. I have tried to enter the actual script where (* Your script goes here *) is... and have placed the location of the .scpt is... and get error back. The Applescript that I want to use runs just by dbleclicking on the file, but can't find a way to get it to run in Automator.

Is there a guide for how to do this somewhere? I have searched this forum and found many other solutions, but not this one for a fairly noob dood trying to use Automator and AppleScript. (My plan is to use something to run the automator once a day to run the script.). Thanks for your help!

Posted on Sep 29, 2023 7:56 AM

Reply
Question marked as Top-ranking reply

Posted on Sep 29, 2023 10:46 AM

Verify that your AppleScript code works in Script Editor before you place it in Automator.


You choose an Automator application and in the workflow, you select the Run AppleScript action. You do as it says, replace (* Your script goes here *) text with your actual copy/pasted script source, not a reference to an external script file. The first line in your Run AppleScript should be use scripting additions and that goes outside of the on run block with a separating space:


use scripting additions


on run {input, parameters}


...blah


end run


Then, you click that hammer icon in the Run AppleScript action, save the Automator application to you Desktop and it will respond to a double-click.

Similar questions

5 replies
Question marked as Top-ranking reply

Sep 29, 2023 10:46 AM in response to OtisMT2

Verify that your AppleScript code works in Script Editor before you place it in Automator.


You choose an Automator application and in the workflow, you select the Run AppleScript action. You do as it says, replace (* Your script goes here *) text with your actual copy/pasted script source, not a reference to an external script file. The first line in your Run AppleScript should be use scripting additions and that goes outside of the on run block with a separating space:


use scripting additions


on run {input, parameters}


...blah


end run


Then, you click that hammer icon in the Run AppleScript action, save the Automator application to you Desktop and it will respond to a double-click.

Sep 30, 2023 9:14 AM in response to OtisMT2

The use scripting additions is innocent here. You should use the following structure when using Run AppleScript in Automator, keeping your handlers separate from the main on run body:


use scripting additions

on run {input, parameters}

your primary applescript code
...
my doWithTimeout(uiScript, timeoutseconds)
return input

end run

on doWithTimeout(uiScript, timeoutSeconds

your handler code
...

end doWithTimeout


Sep 29, 2023 2:35 PM in response to VikingOSX

My script works fine in Script Editor, and also works fine when I double click the 'filename.scpt' in Finder. When I open Automator (and create a new workflow) I add Run AppleScript... with the 'use scripting additions' added to the top, it then finds an error (I guess) with the script that worked fine outside of Automator. Shown below.

Thanks for your help. I'm not sure what is wrong here as I am not a regular code writer. Just trying to get a button pushed on an application twice a day. Thanks. --Otis

Syntax to run AppleScript in Automator

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