![]() ![]() If $_ENV does not get the variable value, it is probably because in the php.ini file E is not included in variables_order. $kmVar = passthru('osascript -e \'tell application "Keyboard Maestro Engine" to getvariable "VarName"\'') If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function. The last line from the result of the command. The exec() command returns the last line of the variable. ![]() Given a KM variable "VarName" with value: this is the new valueĮxecute this command in PHP: exec('osascript -e \'tell application "Keyboard Maestro Engine" to getvariable "VarName"\'', $output) AppleScript.', $output) command return the result as an array, whose elements are lines of the variable value. ![]() The problem is the variable value might already contain \n. In this case, you probably want to use \r instead of \n. But getting only the last line of the variable value via osascript getvariable is an unexpected behavior.) So practically, it might not be a problem at all. If we need the new value, we can update the variable within the PHP code. (To set a KM variable and then read it back to PHP is a rare case. But if osascript gets only the last line of the variable value, it is not reliable. I don't know other ways to get the new KM variable value except using osascript. and is this a bug?Īfter setting the KM variable via osascript, $_ENV and getenv("KMVAR_VarName") no longer reflect the new KM variable value. Getting KM variable values using osascript will get only the last line of the variable value. I've figured out a way to use PHP variables. To demonstrate the point, I've made a PHP script: #!/usr/bin/php I'll give my conclusion here first: If we want to set KM variables, the proper way is to use osascript. Now, setting KM variables in PHP are tricky. Methods 2-4 are used inside the PHP code. $phpVar = exec('osascript -e \'tell application "Keyboard Maestro Engine" to getvariable "VarName"\'') I've posted the method here: Pass KM Variables to PHP in Command Line - Tips & Tutorials - Keyboard Maestro Discourse Pass KM Variables to PHPĪs far as I know, there are three ways to pass KM variables to PHP. I had not thought of it before, but after seeing your reply, I did some tests. Okay, how do you set a Keyboard Maestro variable from PHP? ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |