views:

391

answers:

2

I have a bash script that uses growlnotify to send notifications. However, growlnotify doesn't work if Growl isn't already running, and it won't auto start Growl if it needs it, either. So I want to be able to check if Growl is running, and then start it if it isn't.
I'm thinking of doing something like:

g=$(ps -e | grep Growl | grep -v grep)
if [ -z "$g" ]  # Growl isn't running
then
# (start Growl)
fi

How would I start Growl via the command line?

A: 
pgrep growlnotify || growlnotify <options> &
ghostdog74
No, that's not what i'm asking. I want to check if Growl is running, not growlnotify. And if it isn't, I want to start Growl, not send a message with growlnotify.
adam n
see if you have `growlctl`. use that to start/stop. As for command, you can try grepping for `growl` instead of `Growl` (or give -i to `grep`)
ghostdog74
growlctl was discontinued after Growl version 0.7.6, and the current Growl version is 1.2... Also, it was compiled for PowerPC, so you have to download the Rosetta software to use it on Intel macs. I could have the script download and install Rosetta, and download the old version of Growl to get growlctl, but I'd like to do things as simply as possible. Isn't there an easy way to start a process like Growl from the command line?
adam n
+1  A: 

Normally the Growl installer will ensure that the user doing the installing gets a login Startup item that launches GrowlHelperApp.app, the notification daemon for Growl. The app is built into the Growl PreferencePane, so you can't guarantee where it will be located; it may be in /Library/PreferencePanes or ~/Library/PreferencePanes, depending on how Growl was installed. If you feel you can't trust the user to do the right thing, you can manually launch the helper app from the command line in a location-independent manner by using its bundle identifier:

open -b com.Growl.GrowlHelperApp
Ned Deily
Thank you! that's exactly what i was looking for.
adam n
Well, that almost works. If you look in the system preferences pane afterwards, it will say Growl is running, probably because it checks for GrowlHelperApp in processes. But if you try and use growlnotify, you get an error: "could not find local GrowlApplicationBridgePathway, falling back to NSDNC"
adam n
Works for me. It probably won't work if the user is not connected to the window server. And this is with Growl 1.2 on OS X 10.6.3. No guarantees that it will work with any other combination or that it won't break. The bottom line: if a user wants to use Growl to receive notifications, the user needs to install Growl as documented.
Ned Deily
Really? I'm also using 10.6.3, Growl 1.2, and it doesn't work for me. This is what I did: click the Stop Growl button, then do `open -b com.Growl.GrowlHelperApp`, `growlnotify -m "test"`. This gives the "could not find local GrowlApplicationBridgePathway, falling back to NSDNC" error." If i do: Stop Growl, Start Growl, `growlnotify -m "test"` it works fine. And obviously Stop Growl, `growlnotify -m "test"` produces the error also.
adam n
I don't know if its an issue of the installation of Growl, because that's pretty straightforward. It seems its more that `open -b com.Growl.GrowlHelperApp` doesn't start all the processes necessary to run Growl, which the "Start Growl" button does.
adam n
Well, it was a hack. Unless I misunderstand what you are trying to do, it seems you are trying to work against the design philosophy of Growl. Growl puts user notification under the control of the user. If users choose not to run Growl, then an application should not be trying to start it for them. Or is there something else you are trying to accomplish?
Ned Deily
"If users choose not to run Growl, then an application should not be trying to start it for them." Yes, I guess that's true. Mostly, I was looking for a way to ensure that Growl was running, since my script depends on it. For now, I guess I'm just going to have Terminal run a script that echoes a message telling the user to turn Growl on if it isn't running. Also a hack, but effective.
adam n