Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • by pudge (1) on 2005.03.02 12:48 (#38626) Homepage Journal
    I was working on Mac::Growl, a perl binding for Growl [growl.info]. It originally worked with Foundation, and I made it so that if Foundation is unavailable, it would use Mac::Glue or AppleScript. Then we wanted image support, which I added to the Mac::Glue and AppleScript code, but could not add to the Foundation code, since NSImage and NSWorkspace are in AppKit. Anyway, here's the code I added:
            my $path = NSString->stringWithCString_('/System/Library/Frameworks/AppKit.framework');
            $appkit = NSBundle->alloc->init->initWithPath_($path);
            $appkit->load if $appkit;
            if ($appkit->isLoaded) {
                no strict 'refs';
                for my $class (qw(NSWorkspace NSImage)) {
                    @{$class . '::ISA'} = 'PerlObjCBridge';
                }
            } else {
                undef $appkit;
            }
    Then later:
        if ($appkit && defined $iconOfApp) {
            my $path = NSWorkspace->sharedWorkspace->fullPathForApplication_(
                NSString->stringWithCString_($iconOfApp)
            );
            if ($path) {
                my $icon = NSWorkspace->sharedWorkspace->iconForFile_($path);
                if ($icon && $icon->isValid) {
                    $regDict->setObject_forKey_($icon->TIFFRepresentation, GROWL_APP_ICON);
                }
            }
        }
    and:
        if ($appkit && defined $image && -e $image) {
            my $path = NSString->stringWithCString_($image);
            if ($path) {
                my $icon = NSImage->alloc->initWithContentsOfFile_($path);
                if ($icon && $icon->isValid) {
                    $noteDict->setObject_forKey_($icon->TIFFRepresentation, GROWL_NOTIFICATION_ICON);
                }
            }
        }
    Took me awhile to get it all working, but it is working now. Again, thanks!
    • Glad I could help. My Cocoa-fu is still almost nonexistent, but that was such a good hack I had to put it somewhere I wouldn't lose it.