This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
AppleScript [2017/01/13 20:37] JMichaelTX Last update for @Tom LOL |
AppleScript [2017/06/04 19:06] JMichaelTX [Get Existing Variable] |
||
---|---|---|---|
Line 101: | Line 101: | ||
```applescript | ```applescript | ||
- | --- Requires KM 7.0.2+ --- | ||
- | --- Set AppleScript Variables to KM Variable Name and Value --- | + | set myKMVar to my getKMVar("MY_KM_Variable") |
- | set myKMVar to "My KM Var Name" | + | |
- | set myASVar to "TBD" -- default value of KM variable, will be updated | + | |
- | tell application "Keyboard Maestro Engine" | + | on getKMVar(pKMVarNameStr) |
- | if variable myKMVar exists then | + | |
- | --- GET Existing KM Variable --- | + | --- Compatible with Keyboard Maestro 6+ --- |
- | set myASVar to value of variable myKMVar | + | -- • Returns "" if variable is not found (just like KM 7) |
- | else | + | |
- | --- KM Variable NOT Found --- | + | tell application "Keyboard Maestro Engine" |
- | set myASVar to "" | + | try |
- | -- Optionally, throw an AppleScript error -- | + | set kmVar to value of variable pKMVarNameStr |
- | error "[ERROR] KM Variable '" & myKMVar & "' was NOT found." | + | |
- | end if | + | on error errMsg number errNum |
- | end tell | + | if (errNum = -1728) then |
+ | --- KM Variable NOT Found --- | ||
+ | set kmVar to "" | ||
+ | else | ||
+ | error errMsg | ||
+ | end if | ||
+ | -- END on error | ||
+ | | ||
+ | end try | ||
+ | end tell | ||
+ | |||
+ | return kmVar | ||
+ | | ||
+ | end getKMVar | ||
``` | ``` |