2013-03-18 118 views
1

所以我是新的使用的Automator上OSX變量賦值命令腳本的Automator

我有一個非常簡單的Python功能

def test(input1,input2,output): 
    print str(input1) 
    print str(input2) 
    print str(output) 
    return 'function works' 

我想要做的就是生成一個簡單的應用程序,詢問用於兩個輸入的文件位置和輸出的文件目標(用於輸出的名稱文本框)。

所以我一直在搞亂: 的Automator>選擇工作流程>操作>文件&文件夾>向Finder項(創建其中的兩個)>工具>運行shell腳本

所以我有三個問題:

1。我怎樣才能將這些查找器項目分別分配給我的python腳本中的input1,input2變量?

2。我在哪裏可以將腳本放在接近此代碼的位置?

import sys 

for f in sys.stdin: 
    print f, 

3。參數stdin和參數有什麼區別?

回答

1

完整的工作流程應該是這樣的:

enter image description here

Run Shell Script步驟中,您應該設置Pass Input:as arguments,這樣就可以使用sys.args陣列。您的Python腳本可以像這樣修改:

import sys 

input1 = sys.argv[1] 
input2 = sys.argv[2] 
output = sys.argv[3] 
print input1 
print input2 
print output 

View Results步驟僅用於調試。

如果您將Pass Input:設置爲to stdin,則輸入參數將通過pipeline傳遞給您的腳本。

+0

我似乎無法得到它來創建輸出文件。 Finder&Folders中沒有任何內容可以創建我可以看到的新文件。 。 。另外,我無法得到它打印返回的數據。我在運行Shell腳本後拖動了查看結果,當我運行該應用程序時它不工作(不在automator中) – 2013-03-18 09:03:42

0

你可以簡單地使用AppleScript的:

set inputA to (choose file with prompt "Please choose file one...") 
set inputB to (choose file with prompt "Please choose file two…") 
set outputA to (choose folder with prompt "Please choose a destination…") 

return {((inputA as text) & return & inputB as text) & return & outputA}