BlackDragon Posted October 9, 2016 Share Posted October 9, 2016 Wireless for Alfred Connect to WiFi easily using Alfred 3. Download Get Wireless for Alfred from GitHub Usage wireless <ssid>--The WiFi you want to connect. <ssid> <password>[optional]--if the WiFi has security, you should then extend password next to ssid in the following entry. Results if something goes wrong, the error log will be presented as notification. License MIT License (c) BlackDragonF Link to comment
deanishe Posted October 9, 2016 Share Posted October 9, 2016 Afraid it's broken for me It assumes that en0 is the WiFi interface, but that's en2 on my system (and presumably en1 on machines with one ethernet port). FWIW, you're not using UID properly in your feedback to Alfred. Alfred uses the UID to associate a user's query with the result they select, so it should always be unique to the result (and unchanging). The BSSID would be a better choice (extenders mean it's common to see the same SSID multiple times in results). Link to comment
BlackDragon Posted October 10, 2016 Author Share Posted October 10, 2016 Update. The workflow can find corresponding WiFi interface rather than using en0 without checking - which might cause error when WiFi interface is not en0. And I use BSSID as uid now. I'm now using networksetup -listallhardwareports to get the Device Name from Hardware Port: Wi-Fi. But I'm not sure if there is still something wrong by doing this. Any suggestions will be greatly appreciated. Link to comment
deanishe Posted October 10, 2016 Share Posted October 10, 2016 I think I've found 3 more bugs In lines 10 and 16 of connect.sh, you should use =, not ==, and in line 15, en0 wants replacing with $interface. Personally, I'd skip putting the actual scripts in the Script boxes. It makes it harder to read the code and to understand "error on line X" message (no line numbers, no syntax highlighting). I'd just set the Language to /bin/bash and put /usr/bin/python scan.py in the first Script box and ./connect.sh "{query}" in the second. Obviously, that's a bit slower as you're starting an extra bash process, but that's usually only a few hundredths of a second. I really like the way you parse the output of airport -s. Much better than the regex-based way I came up with last week. Link to comment
BlackDragon Posted October 10, 2016 Author Share Posted October 10, 2016 Thanks a lot for your advice and pointing out my mistakes. It's my carelessness that causes these bugs. And I've fixed them. But actually I'm still confused = with ==, because it seems nothing wrong when I use == in shell scripts. Link to comment
deanishe Posted October 10, 2016 Share Posted October 10, 2016 Tell a lie. That doesn't appear to be what it's complaining about. From my brief research, = and == should be entirely equivalent for strings. I just downloaded the updated version, and I'm still getting the errors: ./connect.sh: line 10: [: en2: unary operator expected ./connect.sh: line 16: [On: command not found I've tinkered with the script a bit, and it seems it's actually the lack of a space after [ I guess the second error is because [$power is being turned into [On and bash is looking for command [On instead of just [ (which is an alias of test, AFAIK). The first error, I dunno. Possibly related to the fact that $interface is " en2", not "en2" (i.e. there's a preceding space)? TBH, bash is a bit black magic to me. I always use [[ and wrap variables in double quotes. Link to comment
BlackDragon Posted October 11, 2016 Author Share Posted October 11, 2016 For the first error, it is actually because of the incorrect separator ':'. And this will cause a preceding space. (but it possibly won't cause bug I guess) Personally, I think it's the lack of a space after [ and a space before ] in both line 10 and 16 that causes the problem. I don't find these bugs because of I use zsh instead of bash, and zsh can run connect.sh correctly. While in bash, the script won't be executed correctly. Now I've added the spaces and modified the separator. I'm new to python and shell script. And it seems like I should learn more before I can have a good command of them. Link to comment
deanishe Posted October 11, 2016 Share Posted October 11, 2016 12 hours ago, BlackDragon said: Personally, I think it's the lack of a space after [ and a space before ] in both line 10 and 16 that causes the problem. We agree then (that's what I said) 23 hours ago, deanishe said: I've tinkered with the script a bit, and it seems it's actually the lack of a space after [ I also use zsh. So much better than bash. Still pretty cryptic, mind you. Link to comment
TomBenz Posted June 30, 2022 Share Posted June 30, 2022 On 10/9/2016 at 3:34 PM, BlackDragon said: Wireless for Alfred Connect to WiFi easily using Alfred 3. Download Get Wireless for Alfred from GitHub How can I connect / switch to my personal hotspot using iPhone using modification of this workflow or others? Password for ssid is already available and stored Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now