Skip navigation

Alfred script to change network location in OS X

  • June 9, 2011 – 18:43
  • Posted in Coding, Mac OS X
  • Tagged alfred, script, useful

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.

spacer

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:

spacer

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

    • jamesoff
    • Posted June 20, 2012 at 11:01
    • Permalink

    My Growl theme is a slightly modified SmokeStack. I can’t remember where I got it, but I uploaded it here for you: 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

    • jamesoff
    • Posted March 11, 2012 at 11:45
    • Permalink

    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)

    • Lucifr
    • Posted August 25, 2011 at 13:07
    • Permalink

    jamesoff: Thank you~

    • jamesoff
    • Posted August 25, 2011 at 08:16
    • Permalink

    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 :)

    • Lucifr
    • Posted August 24, 2011 at 19:02
    • Permalink

    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. By 教程:Mac 的外挂加速「引擎」 Alfred | 猪哥靓 on 03 Mar 2013 at 5:47 am

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

  2. By 5 Awesome Things You Can Do With Alfred On Your Mac on 17 Dec 2011 at 3:51 am

    [...] 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. By 5 Awesome Things You Can Do With Alfred On Your Mac | Apple Stocks on 04 Dec 2011 at 8:44 pm

    [...] 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. By 5 Awesome Things You Can Do With Alfred On Your Mac | on 04 Dec 2011 at 8:28 pm

    [...] 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 [...]

  5. By Alfred Extensions: The best scripts (so far!) « Alfred App – Mac OS X Quicklaunch Application on 02 Aug 2011 at 2:51 pm

    [...] Changing network location jamesoff.net/site/2011/06/09/alfred-script-to-change-network-location-in-os-x/ [...]

Leave a Reply Cancel reply

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

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

gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.