Run Shell Script / embedded script - question re filename

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Hi
Is it possible to pass the matched file, filename.extension into an embedded script.

My embedded script works if I type the filename.extension. The script needs the filename pass to run.

For example: Embedded script has

cd /Users/fullpathtoPythonScript/
python3 pythonscript.py /Users/fullpath/toINPUTfile/textA\(4\).txt

The folder is a "processing folder". Meaning - once hazel matches the file.txt, runs script on the file.txt, the file.txt will be moved out of processing folder.

The filenames of these input files (matched files) unfortunately will sometimes have brackets which I could only get to work in terminal if I put a backslash in front of the bracket.

I tried using "$1" to indicate the filename, like I had previously done, but it did not work. Error in log, was problem with script.

If it is not possible, should I be thinking differently about this. e.g. once match, rename to a generic name, process script etc... (I have this working as a Hazel rule, but am asking as wanted to make sure I am doing the best solution)

first action: rename
rename file (replace ( with A and replace ) withB)

next action: embedded script
cd /Users/fullpathtoPythonScript/
python3 pythonscript.py "$1"

Thankyou for your time and assistance.
Kind regards
NoodleNewbie
 
Posts: 34
Joined: Fri Jul 13, 2018 5:17 pm

Python refers to arguments differently. If you read the instructions above your script, it should note that you should use sys.argv[1]
Mr_Noodle
Site Admin
 
Posts: 11868
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:Python refers to arguments differently. If you read the instructions above your script, it should note that you should use sys.argv[1]


Thankyou
seasea
 
Posts: 10
Joined: Tue May 05, 2015 7:12 am


Return to Support