Run shell script (Perl) - pass success/failure back to Hazel

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

Moderator: Mr_Noodle

I am using "Run shell script" to run some Perl code (happens to be embedded script). I would like to know whether the script succeeded or failed so that I can set a color label on the object file in the next step - green for success, red for failure. Is there a way to do this, or something like it? Can Hazel receive any kind of result back from a script?

Thanks in advance.
severalability
 
Posts: 3
Joined: Mon Dec 23, 2013 11:38 am

Hazel uses a 0 for success (as with any shell script) and any other value for failure so if you have the script return anything besides 0, Hazel will interpret that as an error and stop processing actions on that file.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks for your reply.

Let me re-pose my question slightly differently. Suppose the script can end in either one of two results, neither of which is 'failure' per se: state 'A' or state 'B'. After the script finishes, in Hazel I want to perform different actions depending on the resulting state. Is it possible to pass this information back to Hazel? i.e. Rather than having Hazel stop processing in one state, I want to continue processing in either case.

Thanks.
severalability
 
Posts: 3
Joined: Mon Dec 23, 2013 11:38 am

You can't really split execution paths like that. You can set up a script to run as a condition which will indicate whether the rule matches or not (and if not, processing will continue to process subsequent rules).
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks. That's totally reasonable, I can handle the different execution paths within my script.

I have a separate question or two, but didn't think it warranted starting a new question thread so I'll try asking it here.

I am setting up a system that will monitor to see if an SD card with photos is inserted into my mac, and then process the photos if so. Generally the SD card is called "NO NAME" and it will have a /DCIM directory under which cameras create sub-directories to store its photos e.g. /DCIM/100OLYMP for my E-PL5.

Right now I am monitoring the camera maker sub-directory i.e. /DCIM/100OLYMP rather than either the root directory or /DCIM. This works find most of the time, but sometimes when the SD card is not in my mac (because it is back in the camera, its usual state) Hazel detects that the directory /DCIM/100OLYMP doesn't currently exist. Hazel will then 1) disable (uncheck) the rule, and 2) change the folder icon from blue to light blue with a red X through it. At this point the folder is not being monitored and the rule is not in effect anyway, and this does not change even if I put the SD card back in my mac.

I hope the above is relatively clear. My first question is: is there a way to keep Hazel from disabling the folder monitoring and rule when it detects that the monitored folder temporarily doesn't exist, so that when the SD card is put back in the mac the folder monitoring and rule work normally?

My second question comes about because I am trying to modify my system to get around the above issue. I would like to monitor the folder one level above where the "NO NAME" folder device gets mounted when the SD card is inserted. In Terminal this corresponds to the /Volumes directory, in Finder this corresponds to my mac device name. When I try to add this to the Folders pane in Hazel, while it does show the proper directory when I click "+" to add a folder and click on my mac device, the Open button is grayed out and I am unable to choose this folder to monitor. Is there a way to monitor the /Volumes directory to see if a new disk device has been mounted?

Thanks again.
severalability
 
Posts: 3
Joined: Mon Dec 23, 2013 11:38 am

Hazel keeps an alias as a reference to the folder. If it shows a red X, that indicates that it thinks the folder in question has been deleted instead of just ejected.

As for /Volumes, it's invisible in the open dialog so you have to start typing /Volumes. A text field will pop-up when you type the first / character. This works in the open dialog of any app, btw.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support