将两个项目设置为automator中的shell脚本的输入

时间:2017-08-30 21:45:38

标签: applescript automator

我将此Automator添加为图像的查找服务。

这一切都始于用户选择一堆图像并在服务菜单上选择脚本。

然后脚本首先向用户询问两个问题:

var arrays = [
    [106,142,112,77,115,127,87,127,156,118,91,93,107,151,110,79,40,186],
    [117,139,127,108,172,113,79,128,121,104,105,117,139,109,137,109,82,137],
    [111,85,110,112,108,109,107,89,104,108,123,93,125,174,129,113,162,159],
    [104,153,110,112,108,109,107,89,104,108,123,93,125,174,129,113,162,159]
    /* Can be any amount of arrays */
    ],
    result = [];

//Rounding to nearest whole number.
for(var i = 0; i < arrays[0].length; i++){
  var num = 0;
  //still assuming all arrays have the same amount of numbers
  for(var i2 = 0; i2 < arrays.length; i2++){ 
    num += arrays[i2][i];
  }
  result.push(Math.round(num / arrays.length));
}

alert(result);

当场&#34;在这里它是神奇的线条&#34;我想添加一行,将on run {input, parameters} choose from list {"iPhone", "iPad", "Mac"} with prompt "Choose Platform" set platform to the result as string display dialog "Choose File Name" default answer "" set fileName to the result as string // here it goes the magic line return input end run platform添加为参数(输入?)的数组(?)上的两个条目,这些条目将传递给将跟随此fileName的shell脚本

然后shell脚本将包含以下行:

AppleScript

我不确定shell脚本将如何接收它,但据我所知它应该接收类似于数组的东西,由3个项目组成:平台,文件名和所选文件列表。我知道转移会在输入开头删除该项目。

出于这个原因,我尝试了这些方法:

platform=$1
shift

fileName=$1
shift

for f in "$@"; do

    // files will be processed here

以及

set beginning of input to platform as string and fileName as string

但没有效果。

任何想法

1 个答案:

答案 0 :(得分:1)

这应该照顾你的魔力:

on run {input, parameters}
    set platform to (choose from list {"iPhone", "iPad", "Mac"} with prompt "Choose Platform") as string
    set fileName to text returned of (display dialog "Choose File Name" default answer "") as string
    set tempList to {}
    set end of tempList to platform
    set end of tempList to fileName
    repeat with i from 1 to count of input
        set end of tempList to item i of input
    end repeat
    copy tempList to input
    return input
end run

这也有效,我只是测试了它:

on run {input, parameters}
    set platform to (choose from list {"iPhone", "iPad", "Mac"} with prompt "Choose Platform") as string
    set fileName to text returned of (display dialog "Choose File Name" default answer "") as string
    set beginning of input to fileName
    set beginning of input to platform
    return input
end run

请注意,这只是示例代码,并且不使用任何错误处理。

我相信在这个用例中,您需要一次将一个项目添加到列表中。