User Tools

Site Tools


action:Execute_an_AppleScript

**This is an old revision of the document!**

Execute AppleScript Action

The Execute an AppleScript action executes a specified AppleScript, either from a file or text. For example, say “hello”.

The results of an AppleScript can be:

  • Ignored.
  • Displayed in a floating window.
  • Displayed briefly in a Notification.
  • Typed in to the current selection.
  • Pasted in to the current selection.
  • Saved to a variable.
  • Saved to the system or a Named Clipboard.
  • Asynchronously ignored — the action runs while the macro continues on.

Scripting

For the latest update on this topic, see the User Manual article: 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:

tell application "System Events"
  activate
  display dialog "Hello"
end tell

Using Keyboard Maestro Variables

:!: See Scripting for best methods.

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:

set myVar to do shell script "echo $KMVAR_My_KM_Variable"

However, if setting an AppleScript Variable to a Keyboard Maestro Variable is all you needed to do, then you would use this (requires Ver 7.1+):

tell application "Keyboard Maestro Engine" to set myVar to getvariable "My KM Variable"
action/Execute_an_AppleScript.1489482066.txt.gz · Last modified: 2017/03/14 05:01 by peternlewis