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:

http://localhost:4490/action.html?macro=6368A115-EF3F-4993-8B3F-9699407E71D8&foo=bar

The reason is I want to (at the end of my macro) launch a browser with http://www.%Variable%foo%.com/ where foo could be something different every time.

Thanks!

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:

http://localhost/script.php?input=value

<?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.