Using selected text in macro with run-command

Hi all,

I would like to record a macro which will use the current selected text, or the content from the clipboard (copy/paste) and pass it as a parameter to the command-line dialog, but so far I've had no luck.

The following macro shows what I tried so far:

<?xml version="1.0" encoding="UTF-8"?>
<application>
  <component name="ActionMacroManager">
    <macro name="Something">
      <action id="$Copy" />
      <action id="com.jetbrains.php.framework.FrameworkRunConsoleAction" />
      <typing text-keycode="80:0;72:0;80:0;32:0;45:0;70:0;32:0;84:0;82:0;65:0;78:0;83:0;76:0;65:0;84:0;69:0;59:1;80:0;72:0;80:0;32:0">php -f foo.php</typing>
      <action id="EditorPaste" />
      <action id="EditorEnter" />
      <shortuct text="ENTER" />
    </macro>
  </component>
</application>


It fails during the EditorPaste action, and thus it doesn't paste the actual clipboard content in the console prompt.

Let's say I select the text "Bar" in the editor, and run the macro, then I'd like the following command to be executed:

php -f foo.php bar


Any suggestions would be more than welcome!

Thanks,
Andries

4 comments

Hi Andries,

I think External Tools may be more suitable for this particular job (although not 100% sure as I do not know what exactly you want to achieve) -- and it has $SelectedText$ macro parameter.

File | Settings | External Tools

EDIT:
After I saw your updated post -- I think Extrenal Tools is the way to go.

0

Thank you Andriy Bazanov.

Is it possible to link these external tools to keyboard shortcuts as well?

0

It is meant to be (base on menu structure for Settings | Keymap) .. but it is either not working .. or not implemented yet.

On another hand -- you can access such external tool entry from various places -- in particular from Editor context menu, which is not as convenient as shortcut, but still quick enough.

EDIT:
You can also try to create a macro which will use that external tool (I know, it does not sound solid, but it may work).

0

It appears that you can link a keyboard/mouse shortcut to the exteral tools that are defined:

File > Settings > Keymap > Other


In that list search for the name of the external tool which you defined, select it, and then configure the keyboard shortcut.

Thank you for your quick and helpful answers!

Andries

0

Please sign in to leave a comment.