【问题标题】:How to pass a function and variables to Automator input?如何将函数和变量传递给 Automator 输入?
【发布时间】:2013-12-06 03:33:40
【问题描述】:

我有这样的功能

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:输出有多行。

【问题讨论】:

    标签: shell input automator


    【解决方案1】:

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

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

    【讨论】:

    • Mh.我希望它看起来那么容易和轻松。但是,它不适用于我的脚本(请参阅gist.github.com/pattulus/2c10ac10d727c1cb6fd4)。也许是env bash
    • 它是如何失败的?您使用什么操作来读取输入?
    • 我更新了要点,这样它就可以在没有我传递给它的输入的情况下工作。问题是即使添加详细选项,我也没有得到任何错误输出。文本文件的内容是一个简单的 Markdown 链接,例如 * [Title](http://stackoverflow.com)
    猜你喜欢
    • 2020-12-23
    • 2022-06-10
    • 1970-01-01
    • 1970-01-01
    • 2020-12-20
    • 2011-06-21
    • 1970-01-01
    • 2020-07-28
    • 1970-01-01
    相关资源
    最近更新 更多