Category Archives: Code
title-icon-code

Introducing my Pushover Action for Growl

Since moving my network monitoring and other mobile device notifications across to Pushover, I have missed the ability to forward Growl notifications on my Macs. Growl 2.0 ships with plugins for Boxcar and Prowl, but not Pushover. For simple scenarios like HardwareGrowler being able to tell me when someone has accidentally unplugged a hard drive on my media centre, this was really cool.

With that, here is my Growl-Pushover action style / plugin for Growl 2.0. It has all the usual filters like an idle Mac and minimum priorities, and with the new action configuration engine in Growl 2.0 can be quite powerful in forwarding specific notifications to Pushover.

The plugin is fully open, and the source is available on GitHub. For those who don’t wish to compile it themselves, signed and supported binaries are available on the project page.

Enjoy!

Pushover Action for Growl

title-icon-code

Adjusting the hue of an NSImage

Core Image is fantastic for complex image processing on both Mac OS X and iOS. However, it can also be used for relatively simple image adjustments with just a few lines of code.

This following method snippet adjusts the hue of an NSImage. I use it in an internal app that has colour coded icon status indicators which can’t be easily drawn totally in code. This method means that I can ship one icon resource and change it’s colour at runtime, rather than creating and shipping dozens of coloured icon resources.

As it uses Core Image, you will need to #import <QuartzCore/QuartzCore.h>.

- (NSImage*) adjustImage:(NSImage*)img withHue:(float)hue {

CIImage *inputImage = [[CIImage alloc] initWithData:[img TIFFRepresentation]];

CIFilter *hueAdjust = [CIFilter filterWithName:@"CIHueAdjust"];
[hueAdjust setValue: inputImage forKey: @"inputImage"];
[hueAdjust setValue: [NSNumber numberWithFloat: hue]
forKey: @"inputAngle"];
CIImage *outputImage = [hueAdjust valueForKey: @"outputImage"];

NSImage *resultImage = [[NSImage alloc] initWithSize:[outputImage extent].size];
NSCIImageRep *rep = [NSCIImageRep imageRepWithCIImage:outputImage];
[resultImage addRepresentation:rep];

return resultImage;

}
title-icon-code

Pause & Resume iTunes Downloads with AppleScript

This morning, a Ration user on Twitter commented that it would be cool to script iTunes downloads so that large files could be scheduled for download during off-peak data periods, just like the “Download Apple Software Updates” action already functions.

Scouring through the net and the iTunes AppleScript dictionary, I couldn’t find a way to specifically tell iTunes to pause or resume downloads. As a slightly hacky (but still completely functional) alternative, I cooked up this GUI-scripting AppleScript that should do the trick for most people with some modifications.

Users of Ration can team this with the “Run AppleScript” action to have their downloads resume during off-peak. I can’t think of any clean way to automatically pause all downloads in iTunes on addition, except to pause them as soon as they start.

Eventually, I may clean this up, and include it in Ration as a proper action, but for now, enjoy:

Script on GitHub:gist