Mac Automator: shell script gets only one line

雨燕双飞 提交于 2019-12-24 19:23:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!