PHP Action Plugin


#1

I found keyboard maestro extremely useful, and I think it is quite amazing.

The one action type I did not find was to run an arbitrary PHP script, so I made one.

I chose to convert the parameters and variables to $p{camel case param name} and ${camel case variable name} for convenience (I keep forgetting KMPARAM_ and KMVAR_ , I find them too long).

eg:

A prompt for the user with “User Name” becomes: $userName in the script.

The action can accept either a path to a PHP file, or a PHP script , or both … or non if you find it useful … :smile:

I’ve attached my zip file, as well as an example for usage I hope that others will find this useful.

Please let me know if you have any questions about this (or if it does not work for some reason).

Macro Example:

t.php from the macro:
t.php.zip (199 Bytes)

The PHP script plugin:
PHP Script.zip (11.4 KB)


#2

Nice one. Thanks for sharing!


#3

Nice plugin! But what’s the purpose of the ‘Temporary Folder’ variable?


#4

That’s a very good question ! :slight_smile:

I took a closer look at my code, and I actually hard coded /var/tmp in some places , so there is no reason to have that field on the plugin side of things (it will just confuse some people).

I attached a new version that does not need it.

Essentially the script writes a temporary PHP file when entering raw PHP to the text box, and than it executes it, and cleans it when it is done.

Cheers

Alon
PHP Script.zip (10.4 KB)


#5

ok, this is a new version (yet again), fixed a minor bug …

Cheers

Alon
PHP Script.zip (10.4 KB)


#6

Ok, thank you for the clarification but the new version no longer works :sob:


#7

Well, it took me a “bit” of time. I retested the script, I am not sure where the issue is.

Just in case, I will re-upload the plugin.

Also, please do not forget to run the following command on your keyboard maestro after re-applying the new plugin:

tell application “Keyboard Maestro” to reload
tell application “Keyboard Maestro Engine” to reload

It is described here: http://www.keyboardmaestro.com/documentation/6/pluginactions.html

Please let me know if you still find issues. If you do, please be specific with what you try to achieve.PHP Script.zip (9.6 KB)


#8

Thank you very much. It works now. I probably forgot to reload Keyboard Maestro the first time. Great plugin!


#9

Is it possible to assign the content of the system clipboard to a variable and process this one via PHP within your plugin? Or are only variables accepted that are entered via a prompt?


#10

Yes, any variable defined in Keyboard Maestro should work with the plugin.


#11

Did you get this sorted?
I’ve done a dump of get_defined_vars() and there is no reference in there to get the current clipboard.
How is this done?


#12

Take a look at this example:

What I do in the example below in keyboard maestro, is to get the content of the clipboard, and assign it to a variable named “test”.

In the PHP script, I am simply “echoing” the variable “$v_test”.

Hopefully that makes more sense.

Let me know