4

enter image description here

Ok, this thing is driving me crazy right now. So Action 1 Chooses a Folder (I want to save that folder's path as var_1) and Action 3 Selects a File (I want to save this file's path as var_2)

so in the end . . .

var_1 = '/Users/Prometheus/Desktop/'
var_2 = '/Users/Prometheus/Documents/a.txt'

So how do I use these variables and their values inside of Shell Script with python ? I can't use sys.argv because they are set to some weird variables

I usually put 'Ask for Finder Item' > Run Shell Script and then

import sys

variable = open(argv[1]).read()

but i can't use that in this case . my scripts are in python so i'd rather stay in python because i don't know any other language

2 Answers 2

10

The Automator variables are only used in the Automator workflow. The variable themselves are not directly accessible to either a shell script or a Python script. The Run Shell Script action allows you to pass the values of particular variables to a shell script in either of two ways: either piping them in through stdin or by passing them as execution arguments. For this sort of use case, the latter is easier. To start with, you need to pick Automator variable names in the Set Value of Variable and Get Value of Variable actions so the values selected can be retained between actions. Here's a very rudimentary workflow example where I've selected two folders:

enter image description here enter image description here

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

1 Comment

you have no idea how much you just helped me out thank you so much . your explanation was very good it now makes sense what was happening before!
0

You might use a Run AppleScript action like this to display the dialogs:

POSIX path of (choose folder default location (path to desktop))
result & linefeed & POSIX path of (choose file default location (path to desktop))

Then set "Pass input" to "to stdin" in the Run Shell Script action and use a script like this:

import sys
folder, file = sys.stdin.read().splitlines()

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.