Page 1 of 1

Growl notifications

Posted: Wed Jun 22, 2011 3:03 pm
by jesperbrannmark
You really like the popups from Growl? (Spotify changing song, people logging in to Skype etc)

So do I.

Code: Select all

Procedure Growl_notify(title.s,text.s)
  a.s="try"+#CRLF$
  a.s+"	tell application "+Chr(34)+"GrowlHelperApp"+Chr(34)+#CRLF$
  a.s+"		set the allNotificationsList To {"+Chr(34)+title.s+Chr(34)+"}"+#CRLF$
  a.s+"		set the enabledNotificationsList To {"+Chr(34)+title.s+Chr(34)+"}"+#CRLF$
  a.s+"		register As application "+Chr(34)+ProgramFilename()+Chr(34)+" all notifications allNotificationsList Default notifications enabledNotificationsList icon of application "+Chr(34)+ProgramFilename()+Chr(34)+#CRLF$
  a.s+"		notify With name "+Chr(34)+title+Chr(34)+" title "+Chr(34)+title.s+Chr(34)+" description "+Chr(34)+text.s+Chr(34)+" application name "+Chr(34)+ProgramFilename()+Chr(34)+#CRLF$
  a.s+"	End tell"+#CRLF$
  a.s+"End try"+#CRLF$
  COCOA_AppleScript(a.s)  
EndProcedure
Growl_notify("Here is the title","This is what you want to say")
There is a command line variant for Windows, so I might do something for that as well.
Anyone who got to little to do, maybe find a way to get the notification back (like with skype, if i click on the notification i go straight into chat with that person).

Re: Growl notifications

Posted: Sun Jul 01, 2012 3:54 pm
by jesperbrannmark
Seems like less and less people have growl by default. So I advice to add this code to check for it:

Code: Select all

  temp_a.s="tell application "+Chr(34)+"System Events"+Chr(34)+#CRLF$
  temp_a.s+"	set isRunning To "
  temp_a.s+"		count of (every process whose bundle identifier is "+Chr(34)+"com.Growl.GrowlHelperApp"+Chr(34)+") > 0"+#CRLF$
  temp_a.s+"End tell"
  Global growl_use.s
  growl_use.s=COCOA_AppleScript(temp_a.s)  
if growl_use = "true", then its safe to use.

Re: Growl notifications

Posted: Sun Jul 01, 2012 4:57 pm
by jamirokwai
Hi Jesper,

with this CocoaScript, Growl will use the current Program-Icon of your Application to display the notification...
The CompilerIf-seciton declares some variables to get the correct name of the Application, depending on Debugger or not :-)

Code: Select all


  CompilerIf #PB_Compiler_Debugger
    Global Location$ = ""
    Global MacOSLoc$ = GetPathPart(ProgramFilename())
    Global MacOSXApp$ = Left(MacOSLoc$,FindString(LCase(MacOSLoc$),".app") + 3)
  CompilerElse
    Global Location$ = Left(GetPathPart(ProgramFilename()),FindString(GetPathPart(ProgramFilename()),GetFilePart(ProgramFilename())+".app",1)-1)
    Global MacOSLoc$ = GetPathPart(ProgramFilename())
    Global MacOSXApp$ = Left(MacOSLoc$,FindString(LCase(MacOSLoc$),".app") + 3)
  CompilerEndIf

   title.s = "Growl-Example"
   text.s = "This is a working Example for GROWLing :-)"

    a.s="try"+#CRLF$
    a.s+"   tell application "+Chr(34)+"GrowlHelperApp"+Chr(34)+#CRLF$
    a.s+"      set the allNotificationsList To {"+Chr(34)+title.s+Chr(34)+"}"+#CRLF$
    a.s+"      set the enabledNotificationsList To {"+Chr(34)+title.s+Chr(34)+"}"+#CRLF$
    a.s+"      register As application "+Chr(34)+ProgramFilename()+Chr(34)+" all notifications allNotificationsList Default notifications enabledNotificationsList icon of application "+Chr(34)+MacOSXApp$+Chr(34)+#CRLF$
    a.s+"      notify With name "+Chr(34)+title+Chr(34)+" title "+Chr(34)+title.s+Chr(34)+" description "+Chr(34)+text.s+Chr(34)+" application name "+Chr(34)+ProgramFilename()+Chr(34)+#CRLF$
    a.s+"   End tell"+#CRLF$
    a.s+"End try"+#CRLF$
 

Notification Centre / NSUserNotification

Posted: Fri Jul 27, 2012 6:09 am
by jesperbrannmark
For Mountain Lion, Growl is basicly replaced with Notification Center. It looks much nicer, but havnt had much time to fiddle with it yet.
It seem it can not be called by Applescript without the help of a real program.
It is currently packaged as an application bundle, because NSUserNotification does not work from a ‘Foundation tool’. radar://11956694
(from http://apple.stackexchange.com/question ... pt-or-shel)
It needs a bit of Cocoa code, and there are people here much more fluent with this than me. The code seem to be something like this

Code: Select all

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    NSUserNotification *notification = [[NSUserNotification alloc] init];
    [notification setTitle: @"Title"];
    [notification setSubtitle: @"Subtitle"];
    [notification setInformativeText: @"Informative Text"];

    [notification setHasActionButton: YES];
    [notification setActionButtonTitle: @"Action Button"];
    [notification setOtherButtonTitle: @"Other Button"];

    [notification setSoundName: NSUserNotificationDefaultSoundName];

    [notification setDeliveryDate: [NSDate dateWithTimeIntervalSinceNow: 10]];
    [[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification: notification];
}
( from http://stackoverflow.com/questions/1167 ... ion-button)

I am not at home with making wrappers, anyone else feel tempted? (there is another discussion on the same topic but with a angry mob in it http://stackoverflow.com/questions/1154 ... like-ichat)

Re: Growl notifications

Posted: Fri Jul 27, 2012 6:57 am
by wilbert
The user notification center reserves the right to decide if a delivered user notification is presented to the user. For example, it may suppress the notification if the application is already frontmost (the delegate can override this action). The application can check the result of this decision by examining the presented property of a delivered user notification.
The NSUserNotificationCenterDelegate provides more information about the delivered user notification and allows forcing the display of a user notification even if the application is frontmost.
Would you be content with the default behavior or do you need the delegate method of forcing the display of the notification ?

Re: Growl notifications

Posted: Fri Jul 27, 2012 8:49 am
by jesperbrannmark
Would you be content with the default behavior or do you need the delegate method of forcing the display of the notification ?
I dont know what you mean here. What I want to achieve is simply to put stuff in the notification center. It can show stuff that has happened in programs; like mail, calendar, skype etc.
So I would like to have my own program in there and then put notifications.
Image

Re: Growl notifications

Posted: Fri Jul 27, 2012 9:10 am
by wilbert
Notifications are usually used when an application is not the frontmost one to keep you informed what is going on. If your application is the frontmost one (the one that has focus), the default behavior is that the notification center has the freedom to decide not to present the notification. So my question was simply if you are okay with that or want to force the presentation of your notification even if the application is the one running in the front.

Re: Growl notifications

Posted: Fri Jul 27, 2012 11:24 am
by wilbert
I assumed it would be easy but I can't get it working.
The following code should return the default notification center object (as far as I know) but returns 0 instead.

Edit : code removed since it was not working.

Re: Growl notifications

Posted: Fri Jul 27, 2012 11:53 am
by Polo
I'm currently updating the mac, I'd be interested to see that working, the notification centre is a very cool new feature!

Re: Growl notifications

Posted: Fri Jul 27, 2012 3:25 pm
by wilbert
I tried to create a wrapper but that also doesn't seem to work.
Maybe things get easier once the Cocoa version of PB will be released.

Re: Growl notifications

Posted: Fri Jul 27, 2012 3:34 pm
by Polo
wilbert wrote:I tried to create a wrapper but that also doesn't seem to work.
Maybe things get easier once the Cocoa version of PB will be released.
Maybe the feature is somehow limited to Cocoa/64bits?

Re: Growl notifications

Posted: Fri Jul 27, 2012 4:01 pm
by jesperbrannmark
I read something (I am really working by rumor here, so don't chop my head off) that only signed applications were able to use notification center. In this case we would have to go though the whole code signing process as some of us do when submitting to Mac app store.

Purebasic is probably not signed, and the compiled files are definitely not signed. In this scenario only compiled and signed programs would get a different return than 0 on the sample above - maybe xcode projects in their debugger is OK.. i don't know.

I havn't really tested much of new functions in mountain lion. mostly been struggeling to get my old favorite functions back like ctrl-scroll... so now i am ready to look at it closer.
Really wish I could be of more help here, but I am very lost when it comes to obj-c. Very glad PB makes my life so easy though :)

Here is something http://arstechnica.com/apple/2012/02/gr ... on-center/
The most significant point they raise is that the Mountain Lion notification functionality will only be available to applications that are sold through the Mac App Store. That means many popular applications that are distributed through other channels will potentially not have access to the feature.

Re: Growl notifications

Posted: Fri Jul 27, 2012 4:34 pm
by wilbert
If it supports only signed applications, I won't be able to help out.
I don't have a Mac developer account.

Re: Growl notifications

Posted: Fri Jul 27, 2012 4:58 pm
by Polo
That doesn't sound too good...!

Re: Growl notifications

Posted: Fri Jul 27, 2012 8:56 pm
by jesperbrannmark
I will try to sign this code next week to see if there is a difference.