Page 1 of 1

Run Shell Script / embedded script - question re filename

PostPosted: Thu Jan 28, 2021 12:39 am
by NoodleNewbie
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

Re: Run Shell Script / embedded script - question re filenam

PostPosted: Thu Jan 28, 2021 11:18 am
by Mr_Noodle
Python refers to arguments differently. If you read the instructions above your script, it should note that you should use sys.argv[1]

Re: Run Shell Script / embedded script - question re filenam

PostPosted: Thu Jan 28, 2021 4:11 pm
by seasea
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