Script to connect to bluetooth PAN?

This is my first post on these forums, been reading them all day - so much good info here!

I am trying to create a script that connects my macbook pro to the internet via my phone. I’m using the ‘proximity’ application to run scripts as I (and my phone) move in and out of range my laptop. So far I have it so as I leave it runs the screensaver and locks the screen, and presents me with a log in when I return.

I would like to add to that that when the phone is back in proximity of the laptop a script reconnects to the bluetooth PAN.

Can anyone give me some pointers on where to start? I tried using GUI scripting, but I could only get as as far as opening system preferences and changing the pane to ‘bluetooth’ from there I completely failed to get it to click the menu button and select ‘connect to network’. Of course it would be much nicer if it didn’t have to use GUI scripting, but I’m not sure where to start.