Automating iSync and Bluetooth

With some pointers from friends I've beaten applescript into submission and coded up a script to automate the bluetooth iSync syncing with my phone.
The script opens up System Preferences and enables Bluetooth, then launches iSync and instructs it to sync. It will then leave Bluetooth in the state that it found it in.
The code is below for anyone who might find it handy :) Oh and for the record this is written to run on Mac OS X Leopard.

display dialog "Sync?" buttons {"Ok", "Cancel"} default button 2
if the button returned of the result is "Cancel" then
        stop
end if

tell application "System Preferences"
        activate
        set current pane to pane "com.apple.preferences.Bluetooth"

                tell application "System Events" to tell window "Bluetooth" of process "System Preferences"
                        set was_on to the value of checkbox "On"

                        if value of checkbox "On" is equal to 0 then
                                tell checkbox "On" to click
                        end if
                end tell
        end tell

        tell application "iSync"
                synchronize

                repeat while (syncing is true)
                        delay 5
                end repeat
                set syncStatus to sync status

                if syncStatus is not 2 then
                        if syncStatus = 3 then
                                set syncStatus to "completed with warnings"
                        else if syncStatus = 4 then
                                set syncStatus to "completed with errors"
                        else if syncStatus = 5 then
                                set syncStatus to "last sync cancelled"
                        else if syncStatus = 6 then
                                set syncStatus to "last sync failed to complete"
                        else if syncStatus = 7 then
                                set syncStatus to "never synced"
                        end if
                display dialog "syncStatus: " & syncStatus
        end if
        quit
end tell

if was_on is equal to 0 then
        tell application "System Preferences"
                set current pane to pane "com.apple.preferences.Bluetooth"

                tell application "System Events" to tell window "Bluetooth" of process "System Preferences"
                        if value of checkbox "On" is 1 then
                                tell checkbox "On" to click
                        end if
                end tell
                quit
        end tell
end if

Dual Booting Windows Vista and XP

At work I have 3 Operating systems installed on my PC; Ubuntu Linux, Vista and XP. Originally I only had Ubuntu and Vista, and a big empty portion of the disk intended for XP if I needed it.

Due to these existing partitions, and a USB media card reader, the Windows XP installer would decide label it's system partition "H:", instead of the usual "C:". I'm not sure how much this would have broken, but it annoyed me to the point that I found a hack to fix it.

I found that grub (the linux boot-loader) on my Linux partition allows you to edit the partition table and set the Vista NTFS partition to 'hidden'. The XP installer could still see there was a partition there, but it didn't understand it, and thus labelled it's new partition "C:". XP will of course then proceed to clobber your existing bootloader, but that's a common occurrence, and fixable from a LiveCD, google is your friend here.

You should also be able to use a copy of grub on a LiveCD to mark the partition as (un)hidden if you don't have Linux on your system normally.

Apologies for any vagueness and lack of technical details, this post has been on the back burner for a few months now, and I've actually forgotten most of the details.

Unrestrict BBC Radio iPlayer

As long as I can remember, the BBC's online music streaming service has restricted the control you have on playback streams, restricting the embedded realplayer controls to allow you pause, skip 5 minutes or skip 15 and change the volume. I can understand the legal obligations they may have, but from a piracy perspective stopping people skipping tracks is irrelevant, its only use is as a measure to stop people re-listening to the same track without having to go back to the start each time.

The controls on Mac OS X are less restrictive, but still restrict you to pause, fast forward or stop, however some simple javascript manipulation of the page can enable the regular RealPlayer controls, complete with a seek-bar.

Bookmark either download the source file or view the bookmarklet source. Unfortunately blogger won't let me create an actual bookmarklet link, so you will manually have to save the bookmarklet into a bookmark in your browser.

Google Maps Placemark

This post has been sitting for quite a while now, pending me having time to sit down and write some text to go alongside the code. It would appear that I now have the time to write it up.

Back when I was writing my Google Maps property finder I was using Google's Geocoding API to get a set of co-ordinates based on a search string.

Specifically I was using the getLocations method of the GClientGeocoder object. This would return a number of Placemark objects with a bunch of information about the potential matches. They don't really document this object, but to be honest they don't really need to, below is an example Placemark expressed in JSON-ish notation.

{   "id": "p1",
        "address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
        "AddressDetails": {
                "Country": {
                        "CountryNameCode": "US",
                        "AdministrativeArea": {
                                "AdministrativeAreaName": "CA",
                                "SubAdministrativeArea": {
                                        "SubAdministrativeAreaName": "Santa Clara",
                                        "Locality": {
                                                "LocalityName": "Mountain View",
                                                "Thoroughfare": {
                                                        "ThoroughfareName": "1600 Amphitheatre Pkwy"},
                                                        "PostalCode": {
                                                                "PostalCodeNumber": "94043"
                                                        }
                                                }
                                        }
                                }
                        },
                "Accuracy": 8
                },
        "Point": {
                "coordinates": [-122.081783,37.423111,0]
        }
}

The only thing is, if you want to get a specific element, the tree will not necessarily be the same each time, so traversal is a pain. The code below will condense all this into the root level of an object, so you can pick out the key/value pairs you want, and easily tell if some aren't there.

var Placemark = new Class({
        initialize: function(placemark){
                this.traverse(placemark);
        },
        traverse: function(item, key) {
                for (var key in item) {
                
                        if (key == 'prototype')
                                continue;
                          
                        if(typeof(item[key]) != 'object')
                                this[key] = item[key];
                        else
                                this.traverse(item[key]);
                }
        }
});

One thing to note is that this was written for to use the Mootools class system, though it shouldn't be very hard to remove this dependancy.

Making the most of Pandora.com

Pandora.com is pretty cool, it's been around for a while now but I just went back to it for some easy listening background music to work to. Supposedly they've begun to use IP filtering to limit the audience to the US. Either this is no longer in place or they've made a mistake in a regex somewhere, as this is definitely not the US. I'd forgotten about the limit to the unpaid service, which stops playback after so many songs, but it was quite a while before I actually encountered it. This may be a Mac OS X bug in the flash implementation, but it seems that if you keep the Firefox window containing the player minimised in the Dock, the music doesn't stop playing! Of course this does get in the way of the whole feedback system slightly, but I'm sure there are those who won't mind too much. Once I did encounter the limit I couldn't just refresh the page and go back to listening again as they're smart enough to stop you doing that. But not that smart. To completely stop this you would require either some heinous DRM-spawn system describable as cookies which you can't delete, or some kind of unique client ID, effectively voiding all browser privacy. So to be fair, from the technologies they had to work with, they've done the best they could. ;) So once you've been shut out of the Pandora player try the following:
  1. Delete your cookies from their domains.
  2. Delete any data stored within Adobe Flash for their domain.
The latter can be achieved by opening the Adobe Flash client settings and changing the data limit for the domain to 0KB, which will take effect upon refreshing the page, upon which the flash applet will request to store data in your browser again, and you're back listening, but without any of your stations.

Update:

It appears that the region filtering will go live on January 15th, not quite yet.