10

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?

nightfire
  • 815
  • 2
  • 12
  • 22
  • You can shorten your first two lines to: `if ! ps -e | grep [G]rowl > /dev/null 2>&1` – Dennis Williamson Apr 02 '10 at 04:21
  • thanks. but did you mean `if ! ps -e | grep [Gg]rowl > /dev/null 2>&1` ? anyhow, the process we're looking for will always have Growl.GrowlHelperApp in the name, so you can just grep for uppercase Growl. – nightfire Apr 02 '10 at 05:15
  • No, I didn't mean to check for either case since I knew the process you're looking for starts with a capital G. Doing it the way I showed is a trick to avoid having to do `grep -v` with `ps`. – Dennis Williamson Apr 02 '10 at 05:45

2 Answers2

11

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
  • 83,389
  • 16
  • 128
  • 151
  • 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" – nightfire Apr 02 '10 at 07:33
  • 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 Apr 02 '10 at 07:41
  • 3
    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. – nightfire Apr 02 '10 at 08:26
  • 3
    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. – nightfire Apr 02 '10 at 08:30
  • 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 Apr 02 '10 at 10:02
  • "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. – nightfire Apr 02 '10 at 21:24
0
pgrep growlnotify || growlnotify <options> &
ghostdog74
  • 327,991
  • 56
  • 259
  • 343
  • 1
    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. – nightfire Apr 02 '10 at 02:55
  • 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 Apr 02 '10 at 03:11
  • 2
    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? – nightfire Apr 02 '10 at 04:01