The idea is simple: a 'listener' shell script will watch the download folder for any incoming text file. If the file's content begins with the string cmd=, it will be executed as a shell command. If the header is app=, it will be processed as AppleScript. In both cases, the file will then be deleted. To make it work well, it's better to select "Accept files without warning" in System Preferences -> Bluetooth. As a download folder, I chose /Users -> Shared -> Scripts.
This is the bash script. I saved it as /usr/local/bin/bluecommand (with admin privileges):
#!/bin/bash
# :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# :: Bluecommand - Execute shell commands sent form a bluetooth device ::
# :: 2004 Salvatore Scandurra - http://www.salvatorescandurra.com/ ::
# :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
WORKING_DIR='/Users/Shared/Scripts'
HEADER_COMMAND='cmd='
HEADER_APPLESCRIPT='app='
SECS=10 # Seconds before a new check is performed
echo "Waiting for command files in $WORKING_DIR."
echo "Hit Control-C to exit."
while true
do
for FILE in $WORKING_DIR/*
do
if [ -f "$FILE" ]
then
IS_CMD=`cut -c 1-4 "$FILE"`
if [ "$IS_CMD" == "$HEADER_COMMAND" ]
then
`cat "$FILE" | cut -c 5-`
rm "$FILE"
fi
if [ "$IS_CMD" == "$HEADER_APPLESCRIPT" ]
then
echo `cat "$FILE" | cut -c 5-` | osascript
rm "$FILE"
fi
fi
done
sleep $SECS
done
Here are some examples of what you can now do. Just write them down on a text file on your mobile, and send them to your Mac:
- Using the speech feature: cmd=say hello
- Next track on iTunes: app=tell application "iTunes" to next track
- Opening files and applications: cmd=open /Applications/Mail.app/
- Displaying dialogs: app=tell application "Finder" to display dialog "Yeah!"

