Growl Applescript and no Growl installed
Growl Applescript and no Growl installed
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
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
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
Check it out and post if it is working for you.
Perhaps somebody has a more elegant way to check.
Bye
Jan
Not necessarily... AppleScript is panicky about
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.
Code: Select all
tell application "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.
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.
- zaudragon
- Growl Team
- Posts: 1852
- Joined: Sat Dec 04, 2004 5:05 am
- Location: Kensington, CA, USA
- Contact:
Wow. Why? You could always do: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
Code: Select all
set toppage to do shell script "ps ax | grep --count -i GrowlHelperApp"
if toppage >= 1 then
bla
end ifThe script seems to cognize if growlhelperapp is running but i can't get the growl message to work.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
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
- zaudragon
- Growl Team
- Posts: 1852
- Joined: Sat Dec 04, 2004 5:05 am
- Location: Kensington, CA, USA
- Contact:
Two ways:crashtron wrote:The script seems to cognize if growlhelperapp is running but i can't get the growl message to work.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
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
Code: Select all
tell application myApp to do whateverCode: Select all
tell application "GrowlHelperApp" to do whateverSorry 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.
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*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?
I'll work on getting it back in there.
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:
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
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
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
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?
Sorry about that, and thanks!
-Matt
Sorry about that, and thanks!
-Matt
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.
What are the applescript docs?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?