Pass and set URL parameter as Variable value

Is it possible to pass and set the value of a Variable into a macro via the Web Server?

For example, if I want to set Variable “foo” to a value of “bar”, this doesn’t appear to work:


The reason is I want to (at the end of my macro) launch a browser with where foo could be something different every time.


No, there is no way to do that.

Found a workable solution. Create a PHP script on the machine that accepts the variable from the URL then sets it as a Keyboard Maestro Variable using AppleScript:


<?php $myVariable = $_GET["input"]; exec('osascript -e \'tell application "Keyboard Maestro Engine"\' -e \'make variable with properties {name:"VariableName", value:' . $myVariable . '}\' -e \'end tell\''); ?>
1 Like

That’s a good solution, but just for the record, if that page is globally accessible, using an input parameter from a URL without any encoding like that is a serious security hole. Imagine if the $myVariable variable contains something like:

'}\n tell app "Finder" to erase system harddisk\n …

If the web page is private and inaccessible, thats one thing, but if its possible to get to it from anywhere insecure, that’s a big security hole.

Encoding the variable (quoting any unexpected characters), or failing entirely if the variable does not have the right format would be a good idea regardless.