iPhone and Linux

Sunday, October 25, 2009

Launching scripts from a SpringBoard icon

MobileTerminal is an app that no geek can live without, but it can be a bit of a pain to open, run a command, then close. It can be much nicer if you can create an icon on your SpringBoard which will run your script when tapped.

All you need to do is create a folder named whatever.app in /Applications. These are the files you need to put inside that folder:

An icon named icon.png
A 320x460 background image named Default.png
A plist file which can be copied from another app (or use the one below)
Your bash shell script
A text file named PkgInfo which only contains these 8 characters: APPL????

Edit the plist to point to that script, give it a unique identifier and custom name and voila!, you will have an icon on your springboard which will run your script when tapped.

Here is an example plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

The strings you will need to change are:
CFBundleExecutable - change this to the name of your script
CFBundleIdentifier - this has to be unique for every app/script and in the "reverse DNS" form of "com.apple.mail" It doesn't matter what you enter, as long as it is unique to that app and in that form.
CFBundleName - this is the name that will appear on the SpringBoard.

If you noticed, the script I was using is called vuze.sh. Vuze is the torrent client I use on my home PC. Using the HTML WebUI Plugin and iZUreus, you can control it from a webpage formatted for your iPhone.

You can view it on your local network using the network IP address or remotely using the true IP address. The logical thing to do would be to create a bookmark in Safari to connect to Vuze any time you want, but what if your IP address changes?

I've already talked about monitoring your computer for IP changes with a script but let's rehash it. Run a script like this on your computer:

#! /bin/sh
date > date
ip=$(lynx -dump checkip.dyndns.org | awk '{ print $4 }' | tr -d "\n")
cat ip | grep $ip
then echo "IP hasn't changed. Not sending notification"
# add your notification method here
echo "Sending IP change notification"
# add your notification method here
echo $ip > ip

and any time your home IP changes, the new IP will be sent to your iPhone. I send it via Prowl, but you can use SMS, email or whatever. my IP changes about once a month. Any time I get the notification, I put the new IP in a text file in my home directory so I will always have it and can call it from scripts.

The Vuze script is pretty simple. It gets the IP address from that file and uses the openURL utility from Erica Utilities (available in Cydia) to open Safari to the Vuze control page that is running on my home computer.

#! /bin/sh
ip=$(cat /var/mobile/homeip)
openURL http://$ip:6886

The end result is that I can connect anywhere to the Vuze client by tapping an icon on SpringBoard.

Blog Archive