Run shell script only once without passing input

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

Moderator: Mr_Noodle

I have written a bash script (in a separate file, not embedded into the Hazel rules) which does some image processing on files transferred from a tethered camera. I want Hazel to watch the folder that the files are being transferred to and when the number of files in the folder equals a certain amount, run the script.

The problem is that Hazel wants to run the script on every file in the folder, but the script is not written to use any arguments or input, as it does it's own file gathering and runs on 4 files together, not just 1 at a time.

The script returns an error "2013-10-16 21:26:31.144 hazelworker[3767] Shellscript exited with non-successful status code: 1" when triggered through Hazel, but works perfect when run once in the terminal.

Any ideas?
danforthf
 
Posts: 1
Joined: Wed Oct 16, 2013 9:42 pm

Maybe you should monitor the folder containing the folder you want to process so it only matches once. As for the script error, most scripts ignore extra argument so you need to look at the script and see what it's doing there. Also, try enabling debug mode as that will give you the script output.
Mr_Noodle
Site Admin
 
Posts: 11251
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Sorry I dont think I get what your saying. I try and share what I think you are saying.

Create a rule, where the condition is matching on the FOLDER versus a file within the FOLDER?

Folder "AA". The python script runs on folder "AA" and processes all contents e.g. 10 files, processes 10 files.

Hazel rule:
Example
If folder has contents>0
then run shell script

So your saying, if you match on a Folder critera, the hazel runs once. Whereas if you match on a file criteria, hazel rule runs every time it matches.

Is my understanding close?
NoodleNewbie
 
Posts: 34
Joined: Fri Jul 13, 2018 5:17 pm

If the files you want are in Folder A, instead of monitoring folder A, which will cause Hazel to process each entry in it, have Hazel monitor the folder that contains folder A. Let's call it folder Z.

Now if you monitor folder Z, folder A will be one of the items in it. If you create a rule to match folder A, it will only match it once (since it's only one item).
Mr_Noodle
Site Admin
 
Posts: 11251
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thankyou. I have the logic now and in essence working.

What criteria is best to use so Hazel rule only runs when the 2nd folder has contents?
Otherwise it will always match, and so ends up all day long running the script.

I tried criteria
IF Subfile/folder Count > 0 but it did not work. Hazel rule did not start.

When I removed this criteria, the hazel rule worked
1. ran the script, and the script processed all the files ONCE (yah!)
2. move the files to another folder

but then after a few hours, I had to manually stop hazel as it didnt actually stop attempting to run the script.

Sorta of a loop - which makes sense as the criteria will always be true
e.g
On FOLDER "HazelSingleProcess"
If (and)
name = "books"
kind = folder
then
run embedded shell script (runs the python script)
move files to storage folder
Thankyou for your help.
NoodleNewbie
 
Posts: 34
Joined: Fri Jul 13, 2018 5:17 pm

How about checking whether the folder was modified (which happens anytime a file is added or removed, but if the file is modified)? "Date last modified is after date last matched" should do it.
Mr_Noodle
Site Admin
 
Posts: 11251
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support

cron