User Tools

Site Tools


action:Execute_a_Swift_Script

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_a_Swift_Script [2016/09/13 22:08]
peternlewis
action:Execute_a_Swift_Script [2023/09/12 23:03] (current)
peternlewis [See Also]
Line 17: Line 17:
  
 ===== How to Get Keyboard Maestro Variables ===== ===== How to Get Keyboard Maestro Variables =====
 +
 +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+).
  
 Swift scripts can get (but not set) Keyboard Maestro Variables by using environment variables, for example: Swift scripts can get (but not set) Keyboard Maestro Variables by using environment variables, for example:
Line 40: Line 44:
  
 let myString = "the Value" let myString = "the Value"
-NSAppleScript(source:​ "tell application \"​Keyboard Maestro Engine\"​ to setvariable \"​fromSwift\"​ to \"​\(myString)\""​)?​ +NSAppleScript(source:​ "tell application \"​Keyboard Maestro Engine\"​ to setvariable \"​fromSwift\"​ to \"​\(myString)\""​)?​.executeAndReturnError(nil)
-.executeAndReturnError(nil)+
 </​code>​ </​code>​
  
 Note that if the value might contain backslashes or quotes, you will need to deal with quoting them, replacing every backslash with backslash-backslash,​ and every double quote with backslash-double quote. Note that if the value might contain backslashes or quotes, you will need to deal with quoting them, replacing every backslash with backslash-backslash,​ and every double quote with backslash-double quote.
- 
----- 
  
  
 ===== See Also ===== ===== See Also =====
 +
 +=== Actions ===
 +
 +* [[action:​Execute_a_Shell_Script|Execute a Shell Script]]
 +* [[action:​Execute an AppleScript|Execute an AppleScript]]
 +* [[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]]
  
 ==== Related Wiki Articles ==== ==== Related Wiki Articles ====
action/Execute_a_Swift_Script.1473818896.txt.gz · Last modified: 2016/09/13 22:08 by peternlewis