如何将函数和变量传递给Automator输入?

时间:2013-12-05 19:13:51

标签: shell input automator

我有一个像这样的功能

myText(){
    echo "Title: ${1}"
    echo "Text: ${2}"
}
title="ABC"
text="123"
document=/tmp/temp.txt
myText "${title}" "${text}"

while read line; do
    fillText "${title}" "${text}"
done < "${document}"

...以及接收所选文本的Automator工作流程。

以前我使用过ruby脚本。将内容管道传送到它是没有问题的:

while read line; do
    fillText "${title}" "${text}" | /usr/bin/somescript.rb
done < "${document}"

但是,现在我需要将内容传递给自动播放器工作流程。

Automator可以运行如下工作流程:

automator [-v] [-i input] [-D name=value ...] workflow

所以我试过了:

while read line; do
    output=$(fillText "${title}" "${text}")
    automator -i "${output}" ~/Library/Services/myAutomator.workflow
done < "${document}"

它不起作用。你们中的任何人都知道怎么把它拉下来?

PS:输出有多行。

1 个答案:

答案 0 :(得分:0)

告诉automator通过-作为-i的参数从标准输入读取。

while read line; do
    fillText "${title}" "${text}" | automator -i - ~/Library/Services/myAutomator.workflow
done < "${document}"