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

Use iChat as a command line interpreter Apps
Occasionally, if my internet connection goes down, my computer can be assigned a new IP address. Working remotely, this can be an issue. While I could always use a dynamic DNS client to update a DNS name (i.e. DynDNS) for my computer, I sought to find a more interesting solution.

With some code snippets from several sources and a bit of time later, I came up with an AppleScript application that acts as a command line interpreter for iChat. Using this program, you can select a user to "allow" messages from. When iChat receives an IM from this user, it looks to see if it's one of a few custom commands, if not it tries to run the message as an AppleScript. If that fails, it passes it to the UNIX command line.

In the case of my original proposition, sending ifconfig in the IM will return the current IP address of my computer. Here are a few other possibilities from the Read Me:
  • date: shows the current date
  • ifconfig: gives network status, including current IP address(es)
  • whoami: shows the currently logged on user
  • say "message": your computer will say this message
  • uptime: shows your computer's uptime
You can read more about this on my site, or use a direct download link (116KB, from my site or macosxhints mirror).

[robg adds: I tested this, and it seemed to work as described, though it's a bit strange to receive responses back from a ghost iChat session! The only one that didn't work for me was date, which just returned the word 'date.' Note that certain commands, such as rm, are disabled. The source is also available, in case you'd like to see exactly what's going on. And yes, I realize there's potentially a security concern here, with iChat passing messages to AppleScript and/or the Terminal. But since you have to install and run the app locally, I think it's a mild risk, and there are some useful things that can be done with this app.]
  • Currently 3.00 / 5
  You rated: 5 / 5 (6 votes cast)

Use iChat as a command line interpreter | 7 comments | Create New Account
Click here to return to the 'Use iChat as a command line interpreter' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Authored by: guardian34 on Nov 07, '05 06:42:11AM
robg: The only one that didn't work for me was date, which just returned the word 'date.'

"Date" is being run as an AppleScript (because "date" is a class in AS). If you really wanted to run the UNIX "date" command, you could do something like this:

echo `date`

[ Reply to This | # ]
Use iChat as a command line interpreter
Authored by: sampsa77 on Nov 07, '05 08:00:12AM

This seems like a pretty risky thing to run if you ask me. Maybe add some kind of challenge/response authentication to the protocol, simply running arbitrary Unix commands remotely seems really risky.

And no, simply trusting the iChat servers for authentication isn't enough, it's easy enough to spoof a packet to look like it comes from an iChat server.

Use this with extreme care, especially in production environments.

[ Reply to This | # ]
Authored by: hayne on Nov 07, '05 02:57:27PM

I agree that this is rather risky.
It certainly wouldn't be a good idea to have this running all the time until the security features have been improved.
It might be quite useful however in a remote support situation - you could get your Mum to run this app when needed and then you would be able to control her machine without having to set up a lot of stuff beforehand.

[ Reply to This | # ]
Authored by: pecosbill on Nov 07, '05 03:31:16PM

I agree that this is too risky. Unix is way too powerful to allow full access (despite the attempt at user identification). I would only limit it to selected, pre-written applescripts. Anything else should use SSH as that's what it is for!

Pecos Bill

[ Reply to This | # ]
Authored by: SeanAhern on Nov 08, '05 07:45:50PM

Having Mum run a VNC server would be much more useful, since you could actually "drive" the display. More secure, too.

[ Reply to This | # ]
Use iChat as a command line interpreter
Authored by: jeremywood on Nov 07, '05 03:54:49PM

Wouldn't it be MUCH safer to have your iChat robot tell you the machine's IP address? And then use SSH for remote access, like god intended?

[ Reply to This | # ]
Use iChat as a command line interpreter
Authored by: Dephex Twin on Nov 07, '05 04:14:38PM

Exactly. I was also thinking, there are cheap/free services that let you keep your IP address up to date.

I've used for this in the past. They give you some domain name, you run an app on your computer that tells no-ip (as often as every minute) what your IP address is. The domain name always forwards to your computer's IP. Then you never even have to think about it.

"Knicks suck, Yankees suck, Mets suck..."
"...Krypton sucks"

[ Reply to This | # ]