Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Control a Mac from any Bluetooth-enabled device Network
This trick will let you execute shell scripts and AppleScripts written on Bluetooth-enabled mobiles or handhelds. I wrote it for those phones not compatible with Romeo or Salling Clicker, like my Siemens S55.

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!"
And so on ... yes, the same goal could also be reached via Folder Actions, but I really don't want to have them enabled.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[12,523 views]  

Control a Mac from any Bluetooth-enabled device | 14 comments | Create New Account
Click here to return to the 'Control a Mac from any Bluetooth-enabled device' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Control a Mac from any Bluetooth-enabled device
Authored by: hackamacj on Oct 25, '04 10:38:06AM

This is what I have been looking for to control iTunes with my Palm. SWEET!!!

---
Jacob L. Hackamack
Student
Western Carolina University
704-968-8449
JHackamack@spymac.com



[ Reply to This | # ]
Control a Mac from any Bluetooth-enabled device
Authored by: bearfilm@mac.com on Oct 25, '04 06:29:49PM

Actually Salling Clicker lets you control itunes from a bluetooth palm. If it worked as well as the t610 thenthat will be hard to beat. On the other hand those of us stuck with ipaq pocket pc's (at least myself) woudl jump at the chance to use this!
Good luck and I will keep an eye out for your progress.
If I knew anythign that woudl be usefull, I would offer to help, but alas, I can olnly offer criticism.
Again, Good Luck!



[ Reply to This | # ]
Control a Mac from any Bluetooth-enabled device
Authored by: laurence.wilks on Oct 25, '04 11:30:11AM

Nice idea, but what happens if a user passes a malicious script that (for sake of argument) deletes everything in the root directory?

You do need to be logged on as root or admin to achieve this but as you're not checking any sort of permissions (that I can see) if a user can access root then this could be dangerous.



[ Reply to This | # ]
Control a Mac from any Bluetooth-enabled device
Authored by: bignumbers on Oct 25, '04 11:58:16AM

I don't have any bluetooth palms to test, but I'm guessing the host Macs need to pair with devices (as they do with mice/keyboards) before accepting incoming files. If so, this presents the same risks (low for most situations) as a bluetooth keyboard. Potentially someone could sneak into your office to pair a keyboard, then later hide in your closet and type commands.



[ Reply to This | # ]
Control a Mac from any Bluetooth-enabled device
Authored by: TwoTimes on Oct 25, '04 12:08:01PM

There's no need to pair a device to receive files from it.
Once I left a picture I had on the mobile into every PowerBook at an Apple store!



[ Reply to This | # ]
Control a Mac from any Bluetooth-enabled device
Authored by: TwoTimes on Oct 25, '04 12:04:30PM
Yes, I've been thinking about security. I'm working on a GUI version of the app, and I planned the possibility to require a password in the command to allow execution. The syntax could be:
cmd=pa55w0rd#say hello
I'm adding some other features, like event logging, so expect a main update very soon!

[ Reply to This | # ]
Control a Mac from any Bluetooth-enabled device
Authored by: uzada on Oct 25, '04 02:01:15PM

you could have a list of preselected commands that the script responds too (something equivalent to handlers in xml-rpc) in your script. there is no reason you should be able to do everything from your phone...



[ Reply to This | # ]
Control a Mac from any Bluetooth-enabled device
Authored by: TwoTimes on Oct 25, '04 06:46:59PM

I have much space in the phone memory, so I made a folder of scripts ready-to-go.
If I have to create a 'preselected command', I can just write a bash script, give it a short name, and place it somewhere in my $PATH, so that it will be easily accessible via the phone and via terminal.



[ Reply to This | # ]
Which application for the S55?
Authored by: krid2000 on Oct 25, '04 02:45:50PM

Hi there,

I too own a Siemens S55, and I wonder which of the two apps you are using to control your Mac. Both program's specs don't list the S55 as supported devices.

Thanks,
Dirk



[ Reply to This | # ]
Which application for the S55?
Authored by: TwoTimes on Oct 25, '04 06:51:13PM

My script has nothing to do with any of the two.
But don't worry, my it's quickly growing up into a GUI application! As soon as it will be done I'll share it with you all...



[ Reply to This | # ]
a quick plug...
Authored by: bogdescu on Oct 27, '04 08:41:34AM

...for the very popular but alas rarely supported by Macintoshes
Nokia 6310i.
Thanks!



[ Reply to This | # ]
The GUI is ready!
Authored by: TwoTimes on Oct 27, '04 09:02:29AM
http://www.salvatorescandurra.com/bluecommand/
I've finished working on my application. It's all easier now, and it features a logging system and preferences management.
Please let me know about your experience using it, it's my first app!


[ Reply to This | # ]
Control a Mac from any Bluetooth-enabled device
Authored by: andreas1 on Jul 13, '05 05:47:53AM

I have the application tested it on my computer
I think it doesn't work with tiger
How I can make or save a bash script

thanks
Andreas



[ Reply to This | # ]
Control a Mac from any Bluetooth-enabled device
Authored by: GlowingApple on Jul 13, '05 04:30:15PM

One problem with the Motorola RAZR V3, I can receive and send files just fine if the connection is initiated from my Mac, but I don't know of any way to initiate a send from the RAZR.

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."



[ Reply to This | # ]