2017-08-30 54 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