Jump to content
aiyo

Wi-Fi toggle, Network Location, Fast User Switching, Finder Settings...

Recommended Posts

Hi, I really appreciate the work put into this.

 

 

One note: the "network location" workflow doesn't deal well when the location names have spaces in them....

 

I'll see if I can figure out why it breaks up on spaces, as the "networksetup -listlocations" command doesn't break on spaces

 

 

 

Share this post


Link to post

Hmmm.. grabbed the listing portion of the script and modified it to run in the standard bash shell just to see the output as follows by getting rid of the query lines...

 

 

 

#!/bin/bash


CURRENT_LOCATION=$(networksetup -getcurrentlocation)


echo "<items>"


#if [[ -z "{query}" ]]
#then 
LOCATIONS=$(networksetup -listlocations)
#else
#LOCATIONS=$(networksetup -listlocations | grep -i "{query}") 
#fi


for LOCATION in $LOCATIONS
do
if [[ "$CURRENT_LOCATION" != "$LOCATION" ]]


then echo "<item uid=\"network location $LOCATION\" arg=\"$LOCATION\"><title>$LOCATION</title><subtitle>Network Location</subtitle><icon>icon.png</icon><valid>yes</valid></item>"


fi


done


echo "<item uid=\"\" arg=\"\"><title>$CURRENT_LOCATION (selected)</title><subtitle>Network Location</subtitle><icon>icon.png</icon><valid>no</valid></item>"


echo "</items>"
 

 

 

The output was as follows - with line breaks...

 

 

 

<items>
<item uid="network location Manual" arg="Manual"><title>Manual</title><subtitle>Network Location</subtitle><icon>icon.png</icon><valid>yes</valid></item>
<item uid="network location Automatic" arg="Automatic"><title>Automatic</title><subtitle>Network Location</subtitle><icon>icon.png</icon><valid>yes</valid></item>
<item uid="network location Wired" arg="Wired"><title>Wired</title><subtitle>Network Location</subtitle><icon>icon.png</icon><valid>yes</valid></item>
<item uid="network location In" arg="In"><title>In</title><subtitle>Network Location</subtitle><icon>icon.png</icon><valid>yes</valid></item>
<item uid="network location Google" arg="Google"><title>Google</title><subtitle>Network Location</subtitle><icon>icon.png</icon><valid>yes</valid></item>
<item uid="network location DNS" arg="DNS"><title>DNS</title><subtitle>Network Location</subtitle><icon>icon.png</icon><valid>yes</valid></item>
<item uid="network location Automatic" arg="Automatic"><title>Automatic</title><subtitle>Network Location</subtitle><icon>icon.png</icon><valid>yes</valid></item>
<item uid="network location (Wifi" arg="(Wifi"><title>(Wifi</title><subtitle>Network Location</subtitle><icon>icon.png</icon><valid>yes</valid></item>
<item uid="network location First)" arg="First)"><title>First)</title><subtitle>Network Location</subtitle><icon>icon.png</icon><valid>yes</valid></item>
<item uid="" arg=""><title>Automatic (Wifi First) (selected)</title><subtitle>Network Location</subtitle><icon>icon.png</icon><valid>no</valid></item>
</items>

 

 

 

 

So, when I use the workflow:

 

Screen%20Shot%202013-03-16%20at%2011.27.

Edited by dgarsys

Share this post


Link to post

The heart of the matter seems to be that bash breaks arrays up on spaces.

 

I got the listing right by resetting the $IFS environmental variable to a newline, but that still hasn't allowed me to switch to a new location...

Share this post


Link to post

The heart of the matter seems to be that bash breaks arrays up on spaces.

 

I got the listing right by resetting the $IFS environmental variable to a newline, but that still hasn't allowed me to switch to a new location...

 

You are absolutely right.

 

I've updated the workflow and it should now play nice with locations with spaces.

 

You can download it here (or use the links in the first post) https://github.com/aiyodk/Alfred-Extensions/raw/master/AlfredApp_2.x/Network-Location/Network-Location.alfredworkflow

 

Cheers,

Jonas

 

UPDATE:

I just rewrote the workflow now searching works better.

Edited by Jonas Eriksen

Share this post


Link to post

Thank you - that worked, awesome.

 

At some point I'll have to parse how you worked around that... as sed/awk is not something I'm comfortable with yet.

Share this post


Link to post

Hi, when I try to use the network location workflow I'm asked for admin password and the location isn't changed.

Anything I have to do beside importing the workflow?

I used the 1.x script for a long time with no problems!

 

Thanks alot!

 

Oliver

Share this post


Link to post

Hi, when I try to use the network location workflow I'm asked for admin password and the location isn't changed.

Anything I have to do beside importing the workflow?

I used the 1.x script for a long time with no problems!

 

Thanks alot!

 

Oliver

 

Hi,

 

OSX 10.8 has increased the security in many areas. Because of this "networksetup" (the commandline tool I use in the Network Location Workflow) needs admin privileges for certain tasks. This is why you are requested for the password (it's all done by OSX). If you cancel this request (or mistypes the password or try a username that does not have admin privileges) the network settings are not changed!

 

You could set permission suid to /usr/sbin/networksetup to make it run with root permission, but that opens up for misuse so I won't encourage that.

 

Cheers,

Jonas

Share this post


Link to post

ok, i replaced the command with the line out of the v1 script:

 

/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
 

That seems to work quite well. :-)

Share this post


Link to post

ok, i replaced the command with the line out of the v1 script:

 

/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
 

That seems to work quite well. :-)

 

Thanks! I did not know about scselect. Nice that it does not need elevated privileges.

The other commands is not needed (it is used to trim down the result of scselect). I have updated Network Location to use scselect now!

 

Thanks again!

 

Cheers

Share this post


Link to post

Thanks! I did not know about scselect. Nice that it does not need elevated privileges.

The other commands is not needed (it is used to trim down the result of scselect). I have updated Network Location to use scselect now!

 

Thanks again!

 

Cheers

Your welcome, all credit belongs here : http://jamesoff.net/site/2011/06/09/alfred-script-to-change-network-location-in-os-x/

Share this post


Link to post

I'm trying to get this to pass the selected location name to notification center.  If I use {query} it displays something like "CurrentSet updated to 5775F97D-8B7A-4D2B-578...."

Edited by petebocken

Share this post


Link to post

Excellent workflow!

I have two wifis in my house, which are switched between all day long.

Never did I find such a switch workflow except this kind of On/Off toggles.

Please help~ thank you.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...