Jump to content

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

 

 

 

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

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

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

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

Link to post
  • 2 weeks later...
  • 6 months later...
  • 3 months later...
  • 1 year later...
  • 5 months later...
  • 4 years later...

Sorry to resurrect this old thread, but it seems this fast user switching workflow has (after all these years) stopped working under Big Sur. Anybody have a good, current workflow that lets one quickly switch users using Alfred?

Edited by octothorpe
Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...