Skip navigation

Please see my Alfred Extensions page for updates!

I wrote this little scriptlet to change network location in OS X using Alfred, but you could trigger it using whatever method you wanted.

If you’re using Alfred 0.9.9 or later, you should be able to download this ZIP file and import it!

if you using an earlier version, follow the instructions below:

/usr/sbin/scselect 2>&1 | /usr/bin/grep -i {query} | /usr/bin/cut -c 4-39 | /usr/bin/xargs /usr/sbin/scselect

UPDATE 2011-06-11: I have significantly improved the script to work around a bug caused by the 3Connect profile (3Connect is pants FYI), as well as use growlnotify to tell you if the change worked or not. It also allows substring matches (anchored at the start) so you can use “auto” for “Automatic”. If you have more than one profile that starts with a matching substring, the behaviour is currently undefined.

Growl showing network change notification

MSG=`/usr/sbin/scselect 2>&1 | /usr/bin/egrep -i "\({query}" | /usr/bin/cut -c 4- | /usr/bin/cut -f 1 | /usr/bin/head -n 1 | /usr/bin/xargs /usr/sbin/scselect | /usr/bin/sed -E 's/.+ \((.+)\)/Location changed to \1/'`; if [ "$MSG" = "" ]; then /usr/local/bin/growlnotify -a /System/Library/PreferencePanes/Network.prefPane -m "Unable to change location" Error; else /usr/local/bin/growlnotify -a /System/Library/PreferencePanes/Network.prefPane -m "$MSG" Location changed; fi;

If you want it without Growl notifications, use this version:

usr/sbin/scselect 2>&1 | /usr/bin/egrep -i "\({query}" | /usr/bin/cut -c 4- | /usr/bin/cut -f 1 | /usr/bin/head -n 1 | /usr/bin/xargs /usr/sbin/scselect

It’s slightly convoluted as it’s case-insensitive. To use it, create a Terminal/Shell script entry like this:

Alfred settings

Now you can just type “location work” or similar into Alfred to change network location. I’ll add Growl-confirmation support when the next version of Alfred is released :)

8 Comments

  1. My Growl theme is a slightly modified SmokeStack. I can’t remember where I got it, but I uploaded it here for you: http://cl.ly/1P2A341t1509202m1X0S

    • Charlie
    • Posted June 20, 2012 at 06:40
    • Permalink

    Thanks Bill! I use it every day.

    btw What nice message bubble of growl you have there. Which one is it?

    • clay
    • Posted April 12, 2012 at 13:44
    • Permalink

    great script. very handy. use this everyday. cheers

  2. Hi Bill, you should drag and drop the ZIP file into the Extensions window in Alfred – there’s a thing in the corner which says where to drop to install. No need to extract the files or move them manually :)

    • Bill
    • Posted March 10, 2012 at 18:31
    • Permalink

    HI James, In which place should I paste unzipped plist files? Library/Preferences/ or? Thanks beforehand Alfred 1.1 Mac OS X (10.7.3)

  3. jamesoff: Thank you~

  4. Lucifr: As per the line at the top of the post, please see my Alfred Extensions page. All the versions posted on there are updated to use the new format and features :)

  5. Works like a magic! Thx a lot!

    Would you update it for the latest version of Alfred, plz? It supports growl output now.


5 Trackbacks/Pingbacks

  1. [...] 快速切换网络位置,Alfred script | change network location in OS X [...]

  2. [...] displays it via a Growl notification. There’s also an extension for flushing your DNS cache, changing your Airport network location, and a way to get your network connection speed with [...]

  3. [...] and displays it via a Growl notification. There’s also an extension for flushing your DNS cache, changing your Airport network location, and a way to get your network connection speed with [...]

  4. [...] displays it via a Growl notification. There’s also an extension for flushing your DNS cache, changing your Airport network location, and a way to get your network connection speed with [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>