ActiveState Community

Using self-defined commands in macros

Posted by mikep on 2009-06-04 08:26

Hi
This may be simple, but so far haven't got it right, nor found a solution in the forums.

My goal is to have a hotkey that saves the current (python) file and then runs it. So far I have a command and a macro, which each do half. I want to combine the two, and reference them using the hotkey.

My command is

%(python) "%F"

which runs the program, while the macro is

ko.views.manager.do_cmd_save()

I've tried adding

ko.commands.doCommand('%(python) "%F"')/blockcode>

to the macro, as well using as the command name in the doCommand(). From what I can tell however, I'm limited to using only the predefined set of commands for doCommand(). Is there a simple way to run the python script, or reference the command from the macro?

The runtime error output I get when using the command name is:

Error while running in macro SaveFile:

ReferenceError: compilerun is not defined

exception[message] = compilerun is not defined
exception[fileName] = chrome://komodo/content/project/peMacro.js
exception[lineNumber] = 768
exception[stack] = anonymous([object Object])@chrome://komodo/content/project/peMacro.js:768
macro_evalAsJavascript("ko.views.manager.do_cmd_save()\nko.commands.doCommand(compilerun)\n\n\n",[object XPCWrappedNative_NoHelper],null,[object XULElement])@chrome://komodo/content/project/peMacro.js:775
_executeMacro([object XPCWrappedNative_NoHelper],false,null)@chrome://komodo/content/project/peMacro.js:240
macro_executeMacro([object XPCWrappedNative_NoHelper])@chrome://komodo/content/project/peMacro.js:181
([object XPCWrappedNative_NoHelper],[object MouseEvent])@chrome://komodo/content/project/peMacro.js:84
([object XPCWrappedNative_NoHelper],"ondblclick",[object MouseEvent])@chrome://komodo/content/project/projectExtensionManager.js:498
onDblClick([object MouseEvent])@chrome://komodo/content/bindings/partviewer.xml:325
ondblclick([object MouseEvent])@chrome://komodo/content/komodo.xul:1

exception[name] = ReferenceError

Thanks though for the awesome app - this issue is the last thing I need before it's WAY better than IDLE.
-m

jeffg | Thu, 2009-06-04 09:40

The internal commands you're referring to are not shell commands, and the 'doCommand' method does not support shelling out commands in the way that you want. Fortunately there is a Macro API method for this exact need:

http://docs.activestate.com/komodo/5.1/macroapi.html#macroapi_runencoded...

--
JeffG
http://www.openkomodo.com/blogs/jeffg

mikep | Fri, 2009-06-05 00:29

Hi Jeff

I had looked at runEncodedCommand(), but didn't get it right, so focussed on the doCommand().
It works, thanks!

-m