User Tools

Site Tools


action:Execute_an_AppleScript

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
action:Execute_an_AppleScript [2021/07/21 17:58]
JMichaelTX ADD section on error handling
action:Execute_an_AppleScript [2023/09/12 23:04]
peternlewis [Using Keyboard Maestro Variables]
Line 11: Line 11:
 **There are two setup options:** **There are two setup options:**
 ^ Setup Option ^ Choices\\ (Default shown first) ^ ^ Setup Option ^ Choices\\ (Default shown first) ^
-| Script location | Execute text script (type or paste script into Action text field)\\ Execute script file (This is faster if it is a compiled script file `.scpt`) |+| Script location | Execute text script (type or paste script into Action text field)\\ Execute script file (This may be faster if it is a compiled script file `.scpt`) |
 | Script Results | Ignored.\\ Displayed in a floating window.\\ Displayed briefly in a Notification.\\ Typed in the current text field that has focus.\\ Pasted in text field that has focus.\\ Saved to a Keyboard Maestro Variable.\\ Saved to the System or Named Clipboard.\\ Ignore Results and run //​Asynchronously//​ (the script runs while the macro immediately continues on to the next //​Action//​.) | | Script Results | Ignored.\\ Displayed in a floating window.\\ Displayed briefly in a Notification.\\ Typed in the current text field that has focus.\\ Pasted in text field that has focus.\\ Saved to a Keyboard Maestro Variable.\\ Saved to the System or Named Clipboard.\\ Ignore Results and run //​Asynchronously//​ (the script runs while the macro immediately continues on to the next //​Action//​.) |
  
Line 23: Line 23:
  
 {{:​action:​execute-applescript-example-km8.png?​nolink|}} {{:​action:​execute-applescript-example-km8.png?​nolink|}}
 +
 +When editing the script, you can press <​key>​Enter</​key>​ to compile and format the script, and you can press <​key>​Option-Return</​key>​ (v11.0+) to insert a line break (“¬”) character.
  
 If the script fails, the action will fail (v9.0+), potentially aborting the macro. If the script fails, the action will fail (v9.0+), potentially aborting the macro.
Line 48: Line 50:
  
 :!: **See [[:​AppleScript|Using AppleScript to Get and Set Keyboard Maestro Variables]] for best methods.** :!: **See [[:​AppleScript|Using AppleScript to Get and Set Keyboard Maestro Variables]] for best methods.**
 +
 +Keyboard Maestro sets the environment variables for the script to include all your variables, using a prefix of `KMVAR_` and your variable name with spaces changed in to underscores (‗). For example, your Keyboard Maestro “File Name” variable will be available as the environment variable `KMVAR_File_Name`.
 +
 +By default, all variables are included, but you can select No Variables, or specific variables as desired using the popup menu next to the script (v11.0+).
  
 In AppleScript with Keyboard Maestro Version 7.1+, you can tell the application "​Keyboard Maestro Engine"​ to: In AppleScript with Keyboard Maestro Version 7.1+, you can tell the application "​Keyboard Maestro Engine"​ to:
Line 89: Line 95:
 Here is an example of such an Action/​Macro to handle errors: ​ [[KM] Script Error Handler [Sub-Macro] ](https://​forum.keyboardmaestro.com/​t/​km-script-error-handler-sub-macro/​4641). Here is an example of such an Action/​Macro to handle errors: ​ [[KM] Script Error Handler [Sub-Macro] ](https://​forum.keyboardmaestro.com/​t/​km-script-error-handler-sub-macro/​4641).
  
-  ​ +===== See Also ===== 
-  + 
 +=== Actions === 
 + 
 +* [[action:​Execute_a_Shell_Script|Execute a Shell Script]] 
 +* [[action:​Execute an Automator Workflow|Execute an Automator Workflow]] 
 +* [[action:​Execute a JavaScript For Automation|Execute a JavaScript For Automation]] 
 +* [[action:​Filter|Filter Variable with Expand Tilde In Path]] 
 +* [[:​Actions|See all Actions]] 
 + 
  
action/Execute_an_AppleScript.txt · Last modified: 2023/09/12 23:04 by peternlewis