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

Next revision
Previous revision
Next revision Both sides next revision
action:Execute_an_AppleScript [2015/07/03 00:12]
mirazjordan created
action:Execute_an_AppleScript [2017/06/04 22:45]
JMichaelTX [Using Keyboard Maestro Variables] minor clarification
Line 1: Line 1:
 +{{:​scripting-icon.png?​nolink|}}
 +====== Execute AppleScript Action ======
 +
 The Execute an AppleScript action executes a specified AppleScript,​ either from a file or text. For example, say "​hello"​. The Execute an AppleScript action executes a specified AppleScript,​ either from a file or text. For example, say "​hello"​.
  
Line 11: Line 14:
   *Saved to the system or a Named Clipboard.   *Saved to the system or a Named Clipboard.
   *Asynchronously ignored — the action runs while the macro continues on.   *Asynchronously ignored — the action runs while the macro continues on.
 +
 +===== Scripting =====
 +
 +For the latest update on this topic, see the User Manual article: [[manual:​Scripting|Scripting]].  ​
 +This provides the latest method to get and set Keyboard Maestro variables via AppleScript.
 +
  
 AppleScripts are executed in the background via osascript. This means they are not allowed to do user interaction. You can work around this by asking an application like System Events to do the user interaction for you, for example: AppleScripts are executed in the background via osascript. This means they are not allowed to do user interaction. You can work around this by asking an application like System Events to do the user interaction for you, for example:
Line 18: Line 27:
     display dialog "​Hello"​     display dialog "​Hello"​
   end tell   end tell
 +
 +===== Using Keyboard Maestro Variables =====
 +
 +:!: **See [[:​AppleScript|Using AppleScript to Get and Set Keyboard Maestro Variables]] for best methods.**
 +
 +In AppleScript with Keyboard Maestro Version 7.1+, you can tell the application "​Keyboard Maestro Engine"​ to:
 +
 +    getvariable <KM Variable Name>
 +    setvariable <KM Variable Name> to <New Value>
 +
 +where both the `<KM Variable Name>` and `<New Value>` are text values.
 +
 +For example:
 +<code applescript>​
 +tell application "​Keyboard Maestro Engine"​ to set myVar to getvariable "My KM Variable"​
 +</​code>​
 +---
 +
 +**Using Keyboard Maestro Variables in a Shell Script from AppleScript**
  
 AppleScripts can access variables by using environment variables (using system attribute) or by talking to the Keyboard Maestro Engine. Note that AppleScript’s system attribute is not safe for international characters, although it can use code like: AppleScripts can access variables by using environment variables (using system attribute) or by talking to the Keyboard Maestro Engine. Note that AppleScript’s system attribute is not safe for international characters, although it can use code like:
  
-  ​set to do shell script "echo $KMVAR_Variable"+<code applescript>​ 
 +set myVar to do shell script "echo $KMVAR_My_KM_Variable" 
 +</​code>​ 
action/Execute_an_AppleScript.txt · Last modified: 2023/09/12 23:04 by peternlewis