shell script with growlnotify does nothing

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

Moderator: Mr_Noodle

shell script with growlnotify does nothing Tue May 08, 2012 11:37 pm • by ecormany
i've been trying to figure out what's going wrong here for a few days, and have completely struck out. here's the scenario:

i have a rule that takes any text file on my desktop and automatically makes a symlink in my Dropbox folder. i want to make sure that when i delete one of those text files, the now-broken symlink gets deleted out of Dropbox. i found a one-line script that will trash any broken symlinks.
Code: Select all
find -L ~/Dropbox -type l -exec rm {} \;

i wanted Hazel to give some indication that the symlink had been deleted (in case a link was broken accidentally, i'd want to know to restore it). i wanted to include the name of the symlink, but since that's not the matched file, i couldn't do it with a "Send Growl notification" action. instead, i added a call to growlnotify in my shell script.
Code: Select all
find -L ~/Dropbox -type l -exec growlnotify -a ~/Library/PreferencePanes/Hazel.prefPane -m "$(basename {})" Broken symlink removed -s \; -exec rm {} \;

this script works perfectly from the Terminal, but in my Growl rule it does…nothing. doesn't trigger the Growl notification, doesn't delete the symlink, doesn't throw an error, doesn't show up in the log…just. nothing. i've tried all kinds of sample scripts and it seems to happen in any script that calls growlnotify, even if it's a bare command, rather than a parameter of find.

so, uh, have i done something wrong? is there any workaround? or is this just an odd bug?
ecormany
 
Posts: 28
Joined: Wed Apr 25, 2012 6:15 pm

You might want to specify the full path for any commands you use. You cannot assume that any environment variables are set.

When running on the commandline, run the script with 'sh' and use the --noprofile and --norc flags to see if that better simulates things.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: shell script with growlnotify does nothing Thu May 10, 2012 12:07 pm • by ecormany
thanks for the advice. i was using full paths, i just substituted ~ in my post.

i ran the command (copy/pasted directly out of the Hazel rule) under sh --noprofile --norc and it ran just fine, although it took a couple seconds to display the notification. in my usual shell it happens instantaneously.

a couple other things i noticed. HazelHelper and hazelworker were throwing some errors that weren't showing up in Hazel.log. apparently it's not interpreting the -exec parameter of find as it does on the command line.

Code: Select all
2012/5/9 6:11:13.510 PM [0x0-0x29029].com.noodlesoft.HazelHelper: find:
2012/5/9 6:11:13.510 PM [0x0-0x29029].com.noodlesoft.HazelHelper: growlnotify: No such file or directory

also, i tried running my script from a file instead of as an embedded script. that just went worse.

Code: Select all
2012/5/10 11:38:26.937 AM [0x0-0x20020].com.noodlesoft.HazelHelper: 2012-05-10 11:38:26.936 hazelworker[482:203] *** NSTask: Task create for path '/Users/ed/Documents/Hazel scripts/zap-symlinks.sh' failed: 22, "Invalid argument".  Terminating temporary process.
2012/5/10 11:38:51.844 AM ReportCrash: Saved crash report for hazelworker[482] version 3.0.5 (803) to /Users/ed/Library/Logs/DiagnosticReports/hazelworker_2012-05-10-113851_Emma.crash

i'll keep fiddling with this to see if i can figure out what's wrong.
ecormany
 
Posts: 28
Joined: Wed Apr 25, 2012 6:15 pm

It seems in the first case that you need to specify the full path to growlnotify.

In the second case, it can't run your zap-symlinks.sh script. Maybe you don't have execute permissions on it?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support