问题
I have an Automator script for a service that looks like this:
Receives as text in any application. Input is entire selection, does not replace selected text.
-> Run Shell Script (/bin/bash) "expand -t 4" pass input to stdin
-> Copy to Clipboard
No other options set. The idea is that I can select some code, and put a detabbed version in the clipboard without having to paste the code into BBEdit for detabbing.
The service yields only the first line of the selected text. Deleting the shell-script action puts all of the selected text onto the clipboard. Running
expand -t 4 < /path/to/tabbed.file > result.file
yields the converted contents of the whole input file. Replacing the command with "wc" shows reasonable counts for lines, words, and characters.
So the problem seems to be in passing a selection of more than one line into expand(1) by standard input from an Automator service's input. I don't see anything relevant from the expand(1) man page.
What am I doing wrong?
回答1:
Try this AppleScript:
on run {input}
set the clipboard to (do shell script "expand -t 4 <<< " & quoted form of (input as text))
end run
来源:https://stackoverflow.com/questions/14712079/mac-automator-shell-script-gets-only-one-line