Sunday, 27 September 2009

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
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

Wednesday, 19 August 2009

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.

Labels: , , , ,

Friday, 17 April 2009

Not the medical sort

In contrast to my normal coding related posts, this one is a status update on what I've been up to in the time since the end of my undergraduate degree.

Summer 2008 saw the conclusion of my undergraduate Masters degree in Computer Science, four years of both challenging and interesting work, and a result I am proud of every time it crosses my mind.

Over the summer I undertook another internship with the ALADDIN project; blending HTML, CSS, Java, Javascript and a drop or two of PHP I converted the desktop application I built the previous summer into a cross platform web application. Situational Awareness visualises publicly available weather sensor data in real-time, and is available online.

Come October I started a PhD on Trust and the Semantic Web, supervised by Nicholas Gibbins. So far it's been very interesting, and also in hindsight a very wise decision, given the current economic climate. I'm starting to see where my research is going now and how it fits into the wider picture of the Semantic Web and I'm due to start writing my 9 month progress report soon, which should help crystallise my ideas further.

In my spare time I've joined the Southampton Open Wireless Network society (SOWN) who lend out custom Wireless Access points to students around Southampton, allowing students to share their Wifi with members of the community. It's been a lot of fun, a lot to learn and also a great outlet for any coding urges that I might have.

SOWN have some big news in the pipeline, and it's exciting to see it coming together. We hope to have some media coverage of it closer to the time, so if you're in the Southampton area you probably won't miss it!

Labels: , , ,

Tuesday, 4 November 2008

Not your regular TI-83

I've only ever owned one graphical calculator, a TI-83, which was bought for me around when I started Secondary School. It was the device on which I broke my programming teeth, making crummy games and utilities to make maths exercises less tedious.

The other week I was experimenting with the HTML Canvas element for another little side-project of mine when I was reminded of the Graph Plot screen which my old calculator has. Essentially it lets you enter a Cartesian equation which it will then plot on the screen.

Subsequently, over a couple of days I put together a Javascript powered equation plotter, with much the same functionality as my TI-83. Oh and in the process I found a bug in the WebKit nightly, which they swiftly fixed.

You're free to use the source to the how you wish, if you're that way inclined (it's a client-side web script so it's practically open source off the bat). Under the hood it makes use of the MooTools javascript framework, though I've not made use of its features extensively, so It would only be a matter of an evening's work to remove this dependancy.

Labels: , , ,

Saturday, 23 August 2008

A case of bad cropping

Recently, by pure chance, I've been working for two different research projects which both have involved Java Applets.

The first project ran afoul of bug #6669818 which prevented the applet from connecting back to the originating server during LiveConnect calls, in Mozilla Firefox on a Windows XP platform.

Fortunately there is a workaround for this; by passing the task off to another thread which was started in a non-LiveConnect part of the Applet's lifecycle, the task is then executed in another thread which is not subject to the same malfunctioning security check.

If you'd rather not have to create a thread just for this, a quick hack is to pass the event off to the applet rendering thread using the SwingUtilities.invokeLater(Runnable); function.

In the second project I've now encountered another platform-specific Applet quirk, this time with Mac OSX.

Using Javascript it is possible to change the size of an Applet on the page in the same way you would any other DOM element, however on Mac OSX any browser using the Java Embedding Plugin (Firefox, Opera and others) will fail to resize Java Applets correctly.

I've knocked up a simple test page which allows this to be tested, and shows a potential workaround.

There appear to be two problems cropping up; the first is that the Browser does not notify the Applet that it ought to resize. If you leave the "Notify Java" check-box un-checked when submitting the form, the browser expands the area the Applet ought to be using, but the applet continues to draw in it's original position.

The second issue is that when axis are changed and Java is manually notified the behaviour still does not perform as it ought to. The clipping region of the Java applet rendering is not updated correctly, and thus only part of the applet is correctly rendered.

There is a temperamental workaround for this, by programatically resizing one axis and then the other in quick succession, but this seems to fail as often as it works, depending on whether the page is being loaded from nothing, refreshed, no-cache refreshed or returned to via the browser 'Back' action.

In the interest of getting this bug fixed the code to the Applet resize test page is linked from the test page and free for all to use.

Bugs:


Labels: , , ,