2017-08-30 34 views
1

我有这个Automator作为图像查找服务添加。将两个项目设置为输入到automator中的shell脚本

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

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

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 

现场“这里有云的魔线”我想添加一行,增加阵列上platformfileName为两个条目( ?)的参数(输入?),将传递给将遵循此AppleScript的shell脚本。

shell脚本,然后将这些行:

platform=$1 
shift 

fileName=$1 
shift 

for f in "[email protected]"; do 

    // files will be processed here 

我不知道的shell脚本将如何接收,但据我的理解是应该得到类似的阵列,组成3项:平台,文件名和选择的文件列表。我知道这个转变会在输入开始时删除这个项目。

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

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

set beginning of input to platform 
set beginning of input to fileName 
//hoping it will push platform to the second position 

,但没有奏效。

任何想法

回答

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 

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

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

+0

BRILLIANT!谢谢!!!!!!!!!!!!! – SpaceDog

+0

@SpaceDog,既然你曾经说过你也尝试过'设置输入到平台的开始'我没有打扰测试,只是采取了相反的过程。尽管如此,我只是测试'设置开始输入到fileName',接着在下一行'设置开始输入到平台',它对我很有用。结果是“{”iPhone“,”hello world“,别名”Macintosh HD:Temp:image file 2.png“,别名”Macintosh HD:Temp:imagefile1.png“}'。然后,运行Shell脚本按预期工作。不知道为什么它不适合你。 – user3439894

+0

奇怪,但我的解决方案无法正常工作。 – SpaceDog