2

So I am new at using the Automator on OSX

i have a really simple python function

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

what i want to do is generate a simple application that asks for the file locations of the two inputs and the file destination for the output (name text box for output).

so i have been messing with: Automator > Choose Workflow > Actions > Files & Folders > Ask for Finder Items (Create two of these) > Utilities > Run Shell Script

So I have three questions:

1 . How can I assign these finder items to input1,input2 variables, respectively, on my python script?

2 . Where do I place my script in proximity to this code ?

import sys

for f in sys.stdin:
    print f,

3 . What is the difference between stdin, arguments ?

4

2 回答 2

1

The complete workflow should be something like this:

enter image description here

In the Run Shell Script step you should set Pass Input: to as arguments, so that you can use sys.args array. Your Python script can be modified like this:

import sys

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

View Results step is only for debug.

If you set Pass Input: to to stdin, input arguments are passed to your script via pipeline.

于 2013-03-18T08:34:02.180 回答
0

You could simply use 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}
于 2013-03-18T12:05:43.150 回答