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 ?

0

2 Answers 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.

Sign up to request clarification or add additional context in comments.

1 Comment

i can't seem to get it to create the output file . there's nothing in the Finder & Folders that creates a new file that i can see . . . also, i can't get it to print the data that returns . i dragged View Results after the Run Shell Script and it didn't work when i ran the app (not in automator)
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}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.