User Tools

Site Tools


manual:Scripting

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
Next revision Both sides next revision
manual:Scripting [2017/09/04 02:06]
peternlewis [AppleScript]
manual:Scripting [2018/07/02 19:38]
JMichaelTX Add setup options table
Line 9: Line 9:
   * [[action:​Execute_a_JavaScript_For_Automation|Execute a JavaScript For Automation]]   * [[action:​Execute_a_JavaScript_For_Automation|Execute a JavaScript For Automation]]
   * [[action:​Execute_a_JavaScript_in_Custom_Prompt|Execute JavaScript in Custom HTML Prompt]]   * [[action:​Execute_a_JavaScript_in_Custom_Prompt|Execute JavaScript in Custom HTML Prompt]]
-  * [[action:Execute_a_JavaScript_in_Safari|Execute a JavaScript in Safari]] +  * [[actions:Execute_a_JavaScript_in_Browser|Execute a JavaScript in Browser]]
-  * [[action:​Execute_a_JavaScript_in_Google_Chrome|Execute a JavaScript in Google Chrome]]+
   * [[action:​Execute_a_Shell_Script|Execute a Shell Script]]   * [[action:​Execute_a_Shell_Script|Execute a Shell Script]]
   * [[action:​Execute_a_Swift_Script|Execute a Swift Script]]   * [[action:​Execute_a_Swift_Script|Execute a Swift Script]]
Line 19: Line 18:
 For example, the [[action:​Execute_an_AppleScript]] Action:\\ For example, the [[action:​Execute_an_AppleScript]] Action:\\
 {{:​km-7.3-execute-script.png?​nolink|}}\\ {{:​km-7.3-execute-script.png?​nolink|}}\\
 +
 +**There are two setup options:**
 +^ 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 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 continues on to the next //​Action//​.) |
 +
  
 ==== Getting Script Results ==== ==== Getting Script Results ====
Line 38: Line 43:
 ==== Web Page Interactions ==== ==== Web Page Interactions ====
  
- +The [[actions:Execute_a_JavaScript_in_Browser|Execute a JavaScript in Browser]] actions ​enables deep control over a web page, as well as extracting specific data from both the page contents and HTML.
-JavaScript in a Browser Actions ([[action:Execute_a_JavaScript_in_Google_Chrome|Google Chrome]] and [[action:​Execute_a_JavaScript_in_Safari|Safari]]enables deep control over a web page, as well as extracting specific data from both the page contents and HTML.+
  
 ==== Shell Scripts ==== ==== Shell Scripts ====
- 
  
 Shell scripts can execute any installed scripting language, such as perl, python, ruby or whatever. ​ Be aware that because shell scripts are executed in a non-interactive shell, typically none of the shell configuration files (like CODE{{{.login}}} or CODE{{{.profile}}}) will be executed, which may change the way the shell script behaves. Shell scripts can execute any installed scripting language, such as perl, python, ruby or whatever. ​ Be aware that because shell scripts are executed in a non-interactive shell, typically none of the shell configuration files (like CODE{{{.login}}} or CODE{{{.profile}}}) will be executed, which may change the way the shell script behaves.
- 
  
 Variables can be accessed from shell scripts via the environment variables in the form $KMVAR‗Variable‗Name where KMVAR‗ is prefixed, and spaces are converted to underscores. ​ AppleScripts can also access the environment variables using the CODE{{{system attribute}}} command, but note that CODE{{{system attribute}}} is not safe for international characters. Variables can be accessed from shell scripts via the environment variables in the form $KMVAR‗Variable‗Name where KMVAR‗ is prefixed, and spaces are converted to underscores. ​ AppleScripts can also access the environment variables using the CODE{{{system attribute}}} command, but note that CODE{{{system attribute}}} is not safe for international characters.
Line 169: Line 171:
 </​code>​ </​code>​
  
-You can ask Keyboard Maestro Engine to process tokens for you with:+You can ask Keyboard Maestro Engine to find strings in other scripts:
  
 <code applescript>​ <code applescript>​
 tell application "​Keyboard Maestro Engine"​ tell application "​Keyboard Maestro Engine"​
-  set clip to process tokens ​"%PastClipboard%3%"+   count found in "The Source"​ for "​.e"​ with regex 
 +end tell 
 +</​code>​ 
 + 
 +And you can search and replace with: 
 + 
 +<code applescript>​ 
 +tell application "​Keyboard Maestro Engine"​ 
 + search "​3+4"​ for "​(\\d+)"​ replace ​"%CalculateFormat%CALCULATE(\\1)%Currency%" ​with regex and process tokens
 end tell end tell
 </​code>​ </​code>​
Line 189: Line 199:
 </​code>​ </​code>​
  
-Alternatively you can use the [[/action/​Set_Macro_Enable|Set Macro Enable action]].+Alternatively you can use the [[action:​Set_Macro_or_Group_Enable|Set Macro Enable action]].
  
 You can rename, create, delete, duplicate macro groups and macros. ​ You can add and remove actions. ​ You can get or set the selection. You can rename, create, delete, duplicate macro groups and macros. ​ You can add and remove actions. ​ You can get or set the selection.
Line 207: Line 217:
 ==== Editor ==== ==== Editor ====
  
-Another way you can control Keyboard Maestro ​Editor ​is using the "​`keyboardmaestro`"​ URL scheme, which supports the following formats:+Another way you can control Keyboard Maestro ​editor ​is using the "​`keyboardmaestro`"​ URL scheme, which supports the following formats:
  
 ^ Example Editor URL Command ^ Description ^ ^ Example Editor URL Command ^ Description ^
Line 244: Line 254:
 | `kmtrigger://​macro=Your%20Macro%20Name&​value=Your%20Trigger%20Value` | Using Macro Name with Trigger Value | | `kmtrigger://​macro=Your%20Macro%20Name&​value=Your%20Trigger%20Value` | Using Macro Name with Trigger Value |
 | `kmtrigger://​macro=224AA8CB-07EB-4C92-8201-68FED82B6E9F&​value=Your%20Trigger%20Value` | Using Macro UUID with Trigger Value  | | `kmtrigger://​macro=224AA8CB-07EB-4C92-8201-68FED82B6E9F&​value=Your%20Trigger%20Value` | Using Macro UUID with Trigger Value  |
- 
  
manual/Scripting.txt · Last modified: 2023/10/04 04:27 by peternlewis