-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGeneric Growl Code.scpt
98 lines (86 loc) · 4.1 KB
/
Generic Growl Code.scpt
1
property growlHelperAppName : ""property growlAppName : "Dan's Scripts"property allNotifications : {"General", "Error"}property enabledNotifications : {"General", "Error"}property iconApplication : "OmniFocus.app"(* Begin notification code *)on notify(alertName, alertTitle, alertText) --Call this to show a normal notification my notifyMain(alertName, alertTitle, alertText, false)end notifyon notifyWithSticky(alertName, alertTitle, alertText) --Show a sticky Growl notification my notifyMain(alertName, alertTitle, alertText, true)end notifyWithStickyon IsGrowlRunning() tell application "System Events" to set GrowlRunning to (count of (every process where creator type is "GRRR")) > 0 return GrowlRunningend IsGrowlRunningon dictToString(dict) --needed to encapsulate dictionaries in osascript set dictString to "{" repeat with i in dict if (length of dictString > 1) then set dictString to dictString & ", " set dictString to dictString & "\"" & i & "\"" end repeat set dictString to dictString & "}" return dictStringend dictToStringon notifyWithGrowl(growlHelperAppName, alertName, alertTitle, alertText, useSticky) tell my application growlHelperAppName «event register» given «class appl»:growlAppName, «class anot»:allNotifications, «class dnot»:enabledNotifications, «class iapp»:iconApplication «event notifygr» given «class name»:alertName, «class titl»:alertTitle, «class appl»:growlAppName, «class desc»:alertText end tellend notifyWithGrowlon NotifyWithoutGrowl(alertText) tell application "OmniFocus" to display dialog alertText with icon 1 buttons {"OK"} default button "OK"end NotifyWithoutGrowlon notifyMain(alertName, alertTitle, alertText, useSticky) set GrowlRunning to my IsGrowlRunning() --check if Growl is running... if not GrowlRunning then --if Growl isn't running... set GrowlPath to "" --check to see if Growl is installed... try tell application "Finder" to tell (application file id "GRRR") to set strGrowlPath to POSIX path of (its container as alias) & name end try if GrowlPath is not "" then --...try to launch if so... do shell script "open " & strGrowlPath & " > /dev/null 2>&1 &" delay 0.5 set GrowlRunning to my IsGrowlRunning() end if end if if GrowlRunning then tell application "Finder" to tell (application file id "GRRR") to set growlHelperAppName to name notifyWithGrowl(growlHelperAppName, alertName, alertTitle, alertText, useSticky) else NotifyWithoutGrowl(alertText) end ifend notifyMain(* end notification code *)--Alternate method to call Growlon notifyWithGrowlMethod2(growlHelperAppName, alertName, alertTitle, alertText, useSticky) if useSticky then set osascript to "property growlAppName : \"" & growlAppName & "\"property allNotifications : " & dictToString(allNotifications) & "property enabledNotifications : " & dictToString(enabledNotifications) & "property iconApplication : \"" & iconApplication & "\"tell application \"" & growlHelperAppName & "\" register as application growlAppName all notifications allNotifications default notifications enabledNotifications icon of application iconApplication notify with name \"" & alertName & "\" title \"" & alertTitle & "\" application name growlAppName description \"" & alertText & "\" with stickyend tell" else set osascript to "property growlAppName : \"" & growlAppName & "\"property allNotifications : " & dictToString(allNotifications) & "property enabledNotifications : " & dictToString(enabledNotifications) & "property iconApplication : \"" & iconApplication & "\"tell application \"" & growlHelperAppName & "\" register as application growlAppName all notifications allNotifications default notifications enabledNotifications icon of application iconApplication notify with name \"" & alertName & "\" title \"" & alertTitle & "\" application name growlAppName description \"" & alertText & "\"end tell" end if set shellScript to "osascript -e " & quoted form of osascript & " &> /dev/null &" ignoring application responses do shell script shellScript end ignoringend notifyWithGrowlMethod2my notifyWithSticky("General", "Title", "Body")