External Tools and stdin

I am trying to use AppCode's External Tools feature as a replacement for the wonderful User Scripts feature which, sadly, Apple withdrew in Xcode 4.

I have a Perl script (tool) which I would like to process either the selected text, or all the text in a file, and replace it with the tool output.  My tool expects the text input as stdin and the processed text output is stdout.

How can I route such text to my tool's stdin?  The error I'm getting seems to indicate that the selected text is being passed as an unquoted argument, which is not going to work even if I modify my tool to expect that.

1 comment

Hello Jerry and sorry for the late response.

Looks like External Tool has some limitations (not quoting arguments is just plane stupid). Here how I'd do this:

1) create a proxy script which will receive the main script, file to process and selection lines/columns as its parameters
2) this script will read original file and extract the selected text chunk
3) it will then pass this text to the main script via STDIN and receive processed text from main script's STDOUT
4) after that all that's left is to replace selected text with the processed one and write resulted file contents to the file

I've attached a couple of ugly Ruby scripts as a proof of concept:

- proxy.rb acts as a proxy
- processor.rb is an example of main script which prepends each line in selected text with exclamation marks.

And here is how I've configured this one:



Please sign in to leave a comment.