Created
February 11, 2016 01:34
-
-
Save JMichaelTX/07829fdf62e0f722a14f to your computer and use it in GitHub Desktop.
JXA Functions to Get and Set Keyboard Maestro (KM) Variables using JavaScript for Automation (JXA)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//===================================================================== | |
function setKMVar(pstrName, pstrValue) { | |
//===================================================================== | |
var app = Application.currentApplication() | |
app.includeStandardAdditions = true | |
var appKM = Application("Keyboard Maestro Engine") | |
var oVars = appKM.variables | |
try { | |
oVars[pstrName].name(); | |
} catch (e) { | |
appKM.variables.push(appKM.Variable({'name': pstrName })); | |
app.displayNotification( | |
pstrName, | |
{ | |
withTitle: "Set KM Variable", | |
subtitle: "Variable was Created", | |
soundName: "Basso" | |
}); | |
} // END try/catch | |
oVars[pstrName].value = pstrValue | |
return | |
} // END function setKMVar | |
//––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– | |
//===================================================================== | |
function getKMVar(pstrName) { | |
//===================================================================== | |
var app = Application.currentApplication() | |
app.includeStandardAdditions = true | |
var appKM = Application("Keyboard Maestro Engine") | |
var oVars = appKM.variables | |
try { | |
var strValue = oVars[pstrName].value(); | |
} catch (e) { | |
strValue = undefined | |
app.beep() | |
var oAns = app.displayAlert('KM Variable does NOT exist', { | |
message: 'Var Name: ' + pstrName, | |
as: 'critical' | |
}) | |
} // END try/catch | |
return strValue | |
} // END function getKMVar | |
//––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment