Front Porch

Jaq spent a bit of time this weekend (while I was at the Greenhill Road Touch Fields) emptying out the planter boxes on the front porch, sealing the post that supports the roof, and then we filled the gaps with concrete. Then, we planted some plants! A heap of Snake Plants (Sansevieria trifasciata)__, and a couple of Agave (Agave attenuata). They were all plants we had from the old house, and they look great.

Dsc00008-2 Dsc00009 Dsc00014-1 Dsc00012

State Touch Trials

This weekend was the SASSSA/TouchSA Touch trials. I coach the 15s Girls' team, and we had a great turnout again. More than 40 girls, with most of those of an extremely high standard. We’ve selected a squad of 20 girls who I’ll train over the next month or so, before choosing my final team of 14 and shadows. I’m looking forward to the trip to Darwin in mid-September…

Notification from AppleScript Studio

Christoph asked me for some advice on how to get notification on iTunes track changes in a comment, I said I would write a bit of a tutorial on how I got it to work. First thing was to create an AppleScript Studio program – you will need to have the Developer Tools installed for this. Now, open the main.m file. It should look something like the following:

 1     #import <mach-o/dyld.h>
 2         
 3     extern int _NSApplicationMain_(int argc, const char *argv[]);
 4         
 5     int main(int argc, const char *argv[])
 6     {
 7         if (NSIsSymbolNameDefined("_ASKInitialize"))
 8         {
 9         NSSymbol *symbol = NSLookupAndBindSymbol("_ASKInitialize");
10         if (symbol)
11         {
12         void (*initializeASKFunc)(void) = NSAddressOfSymbol(symbol);
13             if (initializeASKFunc)
14         {
15         initializeASKFunc();
16         }
17         }
18         }
19         
20     return _NSApplicationMain_(argc, argv);
21     }

The file needs to have the following elements. At the start, the following imports are required:

1     #import <Foundation/NSDistributedNotificationCenter.h>
2     #import <Foundation/NSString.h>
3     #import <AppKit/NSAppleScriptExtensions.h>

This should be all of the imports that are required – although I also had stdio.h for a while for testing. After the declaration of the NSApplicationMain, I put the following in:

 1     @interface iTunesConnection : NSObject
 2      - (id) init;
 3     @end
 4     
 5     @implementation iTunesConnection
 6      - (id) init {
 7         NSDistributedNotificationCenter *nc = [NSDistributedNotificationCenter defaultCenter];
 8         [nc addObserver:self
 9                selector:@selector(updateNow:)
10                    name:@"com.apple.iTunes.playerInfo"
11                  object:nil];
12     
13         return self;
14     }
15     
16      - (void) updateNow:(NSNotification *)notification {
17         NSString *updateScript = [NSString stringWithFormat:@"tell application \nend tell"];
18         NSAppleScript *as = [[[NSAppleScript alloc] initWithSource:updateScript] autorelease];
19         [as executeAndReturnError:nil];
20     }    
21     @end

Copy and paste the stuff above – there is some that goes over the line in my browser, but it’s all there if you drag out the selection. You may need to change a couple of things depending on what you want to do. For instance, the @"tell application \nend tell"section needs to be the applescript code that is run whenever a new iTunes track is started, or iTunes is paused. You could fit the entire application into this place, but what I did was have a hidden button that this script “presses”, triggering the update process. Finally, I added the following declaration just after the first brace in the main function declaration:

1     iTunesConnection *connection;
2     connection = [[iTunesConnection **alloc**] init];

This gets everything running. I would suggest putting the following into the applescript string to test it and see that it works:

1     @"tell application \"Finder\"\ndisplay dialog \"iTunes Changed\"\nend tell"

You need to have \" whenever your script would have a ", and \n wherever it would have a newline.