How to run an applescript when connected to a particular network
December 31, 2010 11:31 AM   Subscribe

I want to run a script on my Mac (Applescript most likely) when I connect to a particular wireless router. My Google Fu is failing me. Does anyone know if and how this can be done?

So basically I have a Network attached storage on my work network. (My small company and network) and want to run a few things when I attach to it so I can sync some files between the two (in particular I want to run an rsync job)

I could do this with a cron or something but I'd prefer my computer to just realize that its just connected to the network with the network store on in and attempt the rsync once.

If there's a better way to solve this problem I'd like to hear it, but even so I'd still like to find out if the original problem could be solved. I can think of a few cool things I could do if my computer was smart enough to know "hey I just connected to the home network" or "Hey I just connected to the work network"
posted by bitdamaged to Technology (7 answers total) 3 users marked this as a favorite
 
Best answer: Tada!
posted by dougrayrankin at 11:38 AM on December 31, 2010


I don't know of a way to trigger a script to run when the network configuration changes (which I think is what you want— it would then check to see if you'd just connected to the work router, like how dougrayrankin's link does, and do the rsync). It seems like the sort of thing that Apple's launchd or configd would do (e.g., a launchd key to make launchd run a job when a given SCDynamicStore key changes), but it seems not.

You could write a tiny daemon that sits around and waits for SCDynamicStore notifications and does stuff, but that's more complicated than an Applescript.
posted by hattifattener at 12:08 PM on December 31, 2010


Best answer: Look into Marco Polo. You can set an "Open Action" when a specific wireless network name (SSID) "Rule" changes. It's free and fairly powerful.
posted by Blazecock Pileon at 12:55 PM on December 31, 2010 [2 favorites]


Response by poster: Oooh. Marco Polo looks like it might fit my needs just fine. Tried the script listed earlier it looks like the parsing might be off a bit for my current system and I'm not sure how to trigger it on an event.
posted by bitdamaged at 2:06 PM on December 31, 2010


I rarely have the ability to see what a chain of awk statements will spit out. I would try debugging the AppleScript by starting with the first awk statement and seeing what it outputs, then add more statements until you get what you need.
posted by Blazecock Pileon at 2:16 PM on December 31, 2010


You might also like to look into Do Something When - I remember seeing it aaaages ago, and haven't used it, but who knows - maybe there's an option in there somewhere to help you.
posted by djgh at 8:48 PM on December 31, 2010


Response by poster: So if I spent some time with it I think dougrayrankin's like could have been modified to do what I needed.

However I've gone the Marco Polo route. Does exactly what I needed plus more. Change Default Printer too? Perfect!

Thanks everyone.
posted by bitdamaged at 9:39 AM on January 2, 2011


« Older Linksys mystery   |   Segregated troops at Ft. Gordon, Georgia in 1950s Newer »
This thread is closed to new comments.