如何将变量从ruby脚本传递到automator应用程序?

时间:2011-08-16 09:32:36

标签: ruby parameters automator

所以我在ruby中有一个显然使用变量的脚本。该脚本的一部分打开一个应用程序并运行一个automator工作流程。我的ruby脚本中有一些变量需要我的工作流程才能使用。这有可能吗?

2 个答案:

答案 0 :(得分:0)

你能够: a)从Ruby执行命令行程序 b)将Automator工作流程保存为应用程序

如果是这样,您应该能够运行open命令,例如open test.app --args someArg。或者您可以使用automator命令,例如echo "someArg" | automator -i - test.app

请注意,整个Automator脚本将针对每个参数运行一次 - 尝试将“Speak Text”作为您的第一项验证。

要一次性处理所有参数,您需要实际传递一个然后将其拆分,例如open test.app --args "one|two|three|four"然后像

on run input
    set myArray to my theSplit(input as string, "|")
    set a to item 1 of myArray
    set b to item 2 of myArray
    set c to item 3 of myArray
    set d to item 4 of myArray
    display dialog "c is " & c

        --do stuff
    return str
end run

on theSplit(theString, theDelimiter)
    -- save delimiters to restore old settings
    set oldDelimiters to AppleScript's text item delimiters
    -- set delimiters to delimiter to be used
    set AppleScript's text item delimiters to theDelimiter
    -- create the array
    --set theArray to every text item of theString
    set theArray to text items of theString
    --display dialog theArray as string
    -- restore the old setting
    set AppleScript's text item delimiters to oldDelimiters
    -- return the result
    return theArray
end theSplit

然而,如果AppleScript不是第一个动作,它似乎只能起作用。如果你需要它作为你可能做的第一个动作,首先插入一个只传递参数的Run Shell脚本:

for f
do
  echo “$f"
done

答案 1 :(得分:-1)

是的,可以将参数传递给ruby脚本。这是一个很好的教程:

http://ruby.about.com/od/rubyfeatures/a/argv.htm

相关问题