Growl Applescript and no Growl installed

The Growl forums have moved to Google Groups, this forum is read only.
crashtron
Harmless
Posts: 10
Joined: Wed Aug 03, 2005 5:46 am

Growl Applescript and no Growl installed

Post by crashtron »

Hallo,

I wrote same Applescripts that make use of Growl. Now I want to share this scripts. Growl is just a extra in this scripts so the user don't have to install Growl to use it. But when somebody starts the script and he has Growl not installed he gets an error messages that GrowlHelper.app could not be found. What could I do to eliminate this messages in the case that Growl is not installed?

Thx
crashtron
crashtron
Harmless
Posts: 10
Joined: Wed Aug 03, 2005 5:46 am

Post by crashtron »

I did it by my own. I wrote a small function that checks if Growl is installed on the system. You could get it here http://www.macmediacenter.de/node/89

Check it out and post if it is working for you.

Perhaps somebody has a more elegant way to check.

Bye
Jan
User avatar
nanovivid
Frappa
Posts: 137
Joined: Fri Dec 03, 2004 10:13 pm

Post by nanovivid »

I don't have it with me right now, but there's a way to check if Growl is running. I'll post it once I get home tonight.
DeltaTee
Latté
Posts: 71
Joined: Sun Jun 05, 2005 7:58 pm
Contact:

Post by DeltaTee »

You should just be able to wrap the growl commands in a try ... end try block which would effectively ignore any errors that are produced.
User avatar
nanovivid
Frappa
Posts: 137
Joined: Fri Dec 03, 2004 10:13 pm

Post by nanovivid »

Not necessarily... AppleScript is panicky about

Code: Select all

tell application "SomethingOrOther"

statements where it doesn't know about an app called SomethingOrOther. It'll pop up a box saying "Where is SomethingOrOther?"

In Growl's case, if Growl isn't installed, AppleScript will ask "Where is GrowlHelperApp?" before letting the script run at all. It's a pain.

That's why it's necessary to do some trickery to get around this behavior and fool AppleScript into not looking for GrowlHelperApp until you're sure it's installed.
User avatar
nanovivid
Frappa
Posts: 137
Joined: Fri Dec 03, 2004 10:13 pm

Post by nanovivid »

Here's a function I created for an AppleScript project. It should give you a good idea of what's needed to detect Growl's presence.

Code: Select all

on GrowlNotify(myTitle, myText)
   set myApp to ""
   
   tell application "System Events" to set GrowlRunning to ((application processes whose (name is equal to "GrowlHelperApp")) count)
   
   if GrowlRunning >= 1 then
      try
         set myApp to "GrowlHelperApp"
         
         set appName to "My Spiffy Script"
         set notifs to "{\"Exciting Thing #1\", \"Exciting Thing #2\"}"
         
         tell application myApp to run script "register as application \"" & appName & "\" all notifications " & notifs & " default notifications " & notifs & " icon of application \"Pretty Application\""
         
         tell application myApp to run script "notify with name \"Number Dialed\" title \"" & myTitle & "\" application name \"" & appName & "\" description \"" & myText & "\" icon of application \"Pretty Application\""
      end try
   end if
end GrowlNotify
Last edited by nanovivid on Fri Aug 05, 2005 11:43 pm, edited 1 time in total.
User avatar
zaudragon
Growl Team
Posts: 1852
Joined: Sat Dec 04, 2004 5:05 am
Location: Kensington, CA, USA
Contact:

Post by zaudragon »

nanovivid wrote:Here's a function I created for an AppleScript project. It should give you a good idea of what's needed to detect Growl's presence.

Code: Select all

on GrowlNotify(myTitle, myText)
   set myApp to ""
   
   tell application "System Events" to set GrowlRunning to ((application processes whose (name is equal to "GrowlHelperApp")) count)
   
   if GrowlRunning >= 1 then
      try
         set myApp to "GrowlHelperApp"
         
         set appName to "My Spiffy Script"
         set notifs to "{"Exciting Thing #1", "\Exciting Thing #2"}"
         
         tell application myApp to run script "register as application "" & appName & "" all notifications " & notifs & " default notifications " & notifs & " icon of application "Address Book""
         
         tell application myApp to run script "notify with name "Number Dialed" title "" & myTitle & "" application name "" & appName & "" description "" & myText & "" icon of application "Pretty Application""
      end try
   end if
end GrowlNotify


Wow. Why? You could always do:

Code: Select all

set toppage to do shell script "ps ax | grep --count -i GrowlHelperApp"
if toppage >= 1 then
bla
end if
Blog | X(tras)
Communists code without classes.
crashtron
Harmless
Posts: 10
Joined: Wed Aug 03, 2005 5:46 am

Post by crashtron »

nanovivid wrote:Here's a function I created for an AppleScript project. It should give you a good idea of what's needed to detect Growl's presence.

Code: Select all

on GrowlNotify(myTitle, myText)
   set myApp to ""
   
   tell application "System Events" to set GrowlRunning to ((application processes whose (name is equal to "GrowlHelperApp")) count)
   
   if GrowlRunning >= 1 then
      try
         set myApp to "GrowlHelperApp"
         
         set appName to "My Spiffy Script"
         set notifs to "{"Exciting Thing #1", "\Exciting Thing #2"}"
         
         tell application myApp to run script "register as application "" & appName & "" all notifications " & notifs & " default notifications " & notifs & " icon of application "Address Book""
         
         tell application myApp to run script "notify with name "Number Dialed" title "" & myTitle & "" application name "" & appName & "" description "" & myText & "" icon of application "Pretty Application""
      end try
   end if
end GrowlNotify


The script seems to cognize if growlhelperapp is running but i can't get the growl message to work.

I always get an error message from the script editor "unexpected end of line" or "identifer expected" and so on.

How do I have to escape the script that stand in the "tell application myApp to run script"? Perhaps that is the problem.

thx for the help
User avatar
zaudragon
Growl Team
Posts: 1852
Joined: Sat Dec 04, 2004 5:05 am
Location: Kensington, CA, USA
Contact:

Post by zaudragon »

crashtron wrote:
nanovivid wrote:Here's a function I created for an AppleScript project. It should give you a good idea of what's needed to detect Growl's presence.

Code: Select all

on GrowlNotify(myTitle, myText)
   set myApp to ""
   
   tell application "System Events" to set GrowlRunning to ((application processes whose (name is equal to "GrowlHelperApp")) count)
   
   if GrowlRunning >= 1 then
      try
         set myApp to "GrowlHelperApp"
         
         set appName to "My Spiffy Script"
         set notifs to "{"Exciting Thing #1", "\Exciting Thing #2"}"
         
         tell application myApp to run script "register as application "" & appName & "" all notifications " & notifs & " default notifications " & notifs & " icon of application "Address Book""
         
         tell application myApp to run script "notify with name "Number Dialed" title "" & myTitle & "" application name "" & appName & "" description "" & myText & "" icon of application "Pretty Application""
      end try
   end if
end GrowlNotify


The script seems to cognize if growlhelperapp is running but i can't get the growl message to work.

I always get an error message from the script editor "unexpected end of line" or "identifer expected" and so on.

How do I have to escape the script that stand in the "tell application myApp to run script"? Perhaps that is the problem.

thx for the help


Two ways:

Code: Select all

tell application myApp to do whatever

Code: Select all

tell application "GrowlHelperApp" to do whatever


The latter’s “” are required.
Blog | X(tras)
Communists code without classes.
User avatar
nanovivid
Frappa
Posts: 137
Joined: Fri Dec 03, 2004 10:13 pm

Post by nanovivid »

Sorry about that! I was typing too fast and wrote "\ instead of \" at one point. I've edited my original post to correct it and the corrected version is posted here as well:

Code: Select all

on GrowlNotify(myTitle, myText)
   set myApp to ""
   
   tell application "System Events" to set GrowlRunning to ((application processes whose (name is equal to "GrowlHelperApp")) count)
   
   if GrowlRunning >= 1 then
      try
         set myApp to "GrowlHelperApp"
         
         set appName to "My Spiffy Script"
         set notifs to "{\"Exciting Thing #1\", \"Exciting Thing #2\"}"
         
         tell application myApp to run script "register as application \"" & appName & "\" all notifications " & notifs & " default notifications " & notifs & " icon of application \"Pretty Application\""
         
         tell application myApp to run script "notify with name \"Number Dialed\" title \"" & myTitle & "\" application name \"" & appName & "\" description \"" & myText & "\" icon of application \"Pretty Application\""
      end try
   end if
end GrowlNotify
Last edited by nanovivid on Wed Sep 07, 2005 7:56 pm, edited 1 time in total.
User avatar
The_Tick
Cocoaforge Admin
Posts: 4642
Joined: Thu Dec 02, 2004 6:06 am
Contact:

Post by The_Tick »

Hey nanovivid. When you guys get this figured out, can you add this and http://trac.growl.info/trac/ticket/324 to the applescript docs?
DeltaTee
Latté
Posts: 71
Joined: Sun Jun 05, 2005 7:58 pm
Contact:

Post by DeltaTee »

This code should be equivalent, shorter and easier to use (it sets a boolean):

tell application "System Events" to set GrowlExists to exists application process ("GrowlHelperApp" as string)
User avatar
nanovivid
Frappa
Posts: 137
Joined: Fri Dec 03, 2004 10:13 pm

Post by nanovivid »

The_Tick wrote:Hey nanovivid. When you guys get this figured out, can you add this and http://trac.growl.info/trac/ticket/324 to the applescript docs?


The ironic thing about that is that it was in the original version of the applescript docs that I wrote and somebody removed it, commenting that the docs were too "heavy handed" or something. *shrug*

I'll work on getting it back in there. :)
User avatar
The_Tick
Cocoaforge Admin
Posts: 4642
Joined: Thu Dec 02, 2004 6:06 am
Contact:

Post by The_Tick »

Cool. I have no problem with the docs being verbose.
MattPat
Harmless
Posts: 2
Joined: Wed Sep 07, 2005 7:18 pm

Post by MattPat »

OK, I'm having a problem similar to the original problem (well, not similar, exactly the same). It seems that this problem has not yet been solved.

We've established it's possible to check if Growl is installed in many, many ways. Personally, I just ask the user to tell me, and choose whether they want Growl enabled or not.

The problem is that if AppleScript references another application, it always tries to find that application to check to see if the script is valid-- whether that application actually gets used or not. The only way I've found to circumvent this is to comment out any "tell" line that uses Growl, but I'd really rather not distribute "Growl-enabled" and "Growl-Free" versions of my application.

The only workaround I was able to think up was to create a tiny, false application (with the same dictionary as Growl) that could be distributed with Growl-enabled scripts, and then use "using terms from" to change the dictionary. For example:

Code: Select all

if growlexists is true then
   tell application "GrowlHelperApp"
      using terms from application "FakeGrowl"
         -- put Growl code here
      end using terms from
   end tell
end if


This would work, because AppleScript would look for FakeGrowl (distributed with your script/application) rather than GrowlHelperApp to validate the code, but would send the actual statements to GrowlHelperApp if present. The only problem: that's a lot of work just to get the script to run without an error! (It would admittedly become easier if someone create the app, then posted it online for everyone to use, but that's still a lot of work).

The question is: is it possible to make AppleScript not try to validate the code inside tell blocks (or is there another way to make it work without having to create a fake Growl)?

Thanks

-Matt
User avatar
nanovivid
Frappa
Posts: 137
Joined: Fri Dec 03, 2004 10:13 pm

Post by nanovivid »

Matt, look at my code posted above. It detects Growl's presence without the "Where is GrowlHelperApp" box popping up.
MattPat
Harmless
Posts: 2
Joined: Wed Sep 07, 2005 7:18 pm

Post by MattPat »

I never copied the code verbatim (and actually, still haven't) and my scripts weren't working, but that's because I was missing the key piece that made it work. I too tried putting the app name in a variable, but never surrounded it in the try block. Kinda' weird that that actually works... but who's complaining, since it does work? :wink:

Sorry about that, and thanks!

-Matt
soj
Muffin
Posts: 41
Joined: Tue Aug 29, 2006 5:12 am

Post by soj »

Code: Select all

try
	set growlFound to false
	set growlSubPath to "PreferencePanes:Growl.prefpane"
	set growlLocalPath to (path to library folder from local domain as string) & growlSubPath
	set growlUserPath to (path to library folder from user domain as string) & growlSubPath
	
	-- look for growl in computer's library and user's library 
	if exists file growlLocalPath then
		set growlFound to true
		open file growlLocalPath
	end if
	if exists file growlUserPath then
		set growlFound to true
		open file growlLocalPath
	end if
	if growlFound is false then error
	
on error errMsg number errNum
	
	(* whatever you want the script to do if growl is not installed. *)

	
end try
Last edited by soj on Thu Aug 23, 2007 10:44 pm, edited 1 time in total.
soj
Muffin
Posts: 41
Joined: Tue Aug 29, 2006 5:12 am

Post by soj »

The_Tick wrote:Hey nanovivid. When you guys get this figured out, can you add this and http://trac.growl.info/trac/ticket/324 to the applescript docs?
What are the applescript docs?
User avatar
The_Tick
Cocoaforge Admin
Posts: 4642
Joined: Thu Dec 02, 2004 6:06 am
Contact:

Post by The_Tick »

They're documents describing how to use our applescript api. It's up on the website under the documentation area.
Locked