Jump to content

Recommended Posts

I've made a lot of progress but stuck with this wifi picker workflow - its based off the Eject workflow, and I'm hung in 2 places - getting data to flow from python into the Alfred feedback module, and getting it to flow from the script filter to the bash script.


What's working and isn't pretty well documented in the code. There have been a lot of requests for this workflow so Any and all help appreciated.


Edited by anthonymobile
Link to comment

Your link is a 404. It should be https://github.com/anthonymobile/Alfred-WifiPicker (as far as I can tell).
The first problem with your workflow is that in GetNetworks.py, you're trying to add a variable that doesn't exist (mac) to your network_tuples list.
There are some other minor problems with the code (like using len(self.feedback) for the uid of results), but that's the first obvious showstopper.


Before trying to write a workflow, I would recommend writing a version of your critical function(s) that work on the command line. It's much easier to debug that way.

Edited by deanishe
Link to comment

I've had another look at the code, and there are a few more issues that mean it won't work as a workflow as-is.
"Debug.py" doesn't appear to be in use, but there's the same issue with using undefined variables (address and strength).
You must not use print in Script Filters unless you redirect its output.
By default print sends its output to STDOUT, which is where Alfred reads its input from. In a Script Filter, the print output will get mixed in with the XML output to Alfred, making it invalid.
For debugging output, you should use the logging library or redirect the output to STDERR:

import sys
print >> sys.stderr, "text here"

It's probably better to use the print function:

from __future__ import print_function
import sys

print("text here", file=sys.stderr)
Link to comment

thanks. i've addressed a number of these things (still learning Python along the way). got the script to where its pushing back the MAC addresses but not the SSIDs, and they are displaying properly in the Alfred feedback dialog, so that's progress!

Edited by anthonymobile
Link to comment

Well, the XML output is actually a plist, so you'll find it a lot easier to parse using plistlib instead of ElementTree.


As far as I can tell, MAC addresses are irrelevant. What you need is the SSIDs of available networks and the device name of your WiFi card (e.g. en0, en1, en2 etc.).


To get the SSIDs of available networks, use:


import plistlib
import subprocess
xml = subprocess.check_output(
networks = plistlib.readPlistFromString(xml)
for network in networks:

According to the man page, the way to connect to a wireless network is:


networksetup -setairportnetwork [interface] [router SSID] [password]

The big problem is, as I see, it figuring out which network interface is the WiFi card. On my MacPro for example, it's en2 (because it has two built-in ethernet ports). It'll be en0 on all notebooks (I assume), but not on desktop machines with ethernet ports. That said, if changing WiFi networks is something you need to do regularly, you're almost certainly using a MacBook, and all but the oldest of them only have one NIC (the WiFi one).


This is one of the main reasons I wrote a workflow based on Network Locations instead of WiFi networks.

Edited by deanishe
Link to comment

By the way, you shouldn't put *.pyc files in your Git repos. They're temporary compiled files and won't work on different versions of Python. If you wrote the workflow in Python 2.7, it probably won't work for someone on 2.6 without deleting the *.pyc files first.

Add *.pyc to your .gitignore file.

Link to comment

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