Mac Automator:Shell脚本仅获得一行 [英] Mac Automator: shell script gets only one line

查看:150
本文介绍了Mac Automator:Shell脚本仅获得一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务的Automator脚本,如下所示:

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

未设置其他选项.我的想法是,我可以选择一些代码,然后在剪贴板中放置一个已取消标签的版本,而不必将代码粘贴到BBEdit中以进行取消标签.

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.

该服务仅产生所选文本的第一行.删除shell脚本操作会将所有选定的文本放到剪贴板上.正在运行

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

产生整个输入文件的转换内容.将命令替换为"wc"会显示出合理的行数,单词数和字符数.

yields the converted contents of the whole input file. Replacing the command with "wc" shows reasonable counts for lines, words, and characters.

因此,问题似乎出在从Automator服务的输入中通过标准输入将多行选择传递到expand(1)中.在expand(1)手册页中没有看到任何相关的内容.

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.

我在做什么错了?

推荐答案

尝试使用此AppleScript:

Try this AppleScript:

on run {input}
    set the clipboard to (do shell script "expand -t 4 <<< " & quoted form of (input as text))
end run

这篇关于Mac Automator:Shell脚本仅获得一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆