ixium Posted June 14, 2016 Posted June 14, 2016 Not really sure where to put this, but I have an idea and no idea how to implement it. At work, our internet goes out quite a bit, my wifi stays active and full, so I have to open a new window, type something random into google and see if it works to know if the net is down and if it needs to be restarted. I could make a workflow that launches a google window and iinputs some random stuff, but can anyone think of a more elegant solution, a one word test that can be run through alfred and give me the result (connected or no connection) in alfred as well. thank you so much!
deanishe Posted June 14, 2016 Posted June 14, 2016 The shell command ping -o -t 2 google.com will succeed if it can connect to Google and fail if not (-t 2 means 2-second timeout, so you might need to increase that). Here's a simple bash script: ping -o -t 2 google.com if [[ $? -eq 0 ]]; then echo "Online" else echo "Offline" fi Put that in a Run Script Action (Language = /bin/bash) and connect it to a Post Notification or Large Type Output.
ixium Posted June 14, 2016 Author Posted June 14, 2016 thank you so much, I believe that worked perfectly and you taught me some new stuff, like pushing to large type. Very cool. thank you so much!
nikivi Posted June 14, 2016 Posted June 14, 2016 (edited) Can I ask a question regarding this workflow? I also find it quite insightful that something like this can be done. I tried to replicate it like so : this is what I wrote in the bash script : And this is the post notification : However I would assume that the post notification would only write me 'online' or 'offline' in the notification but instead it writes this : I am not really certain what clarifies as a query here? Is it the echo part or everything in the script and how can I specify what goes in the notification pane. Thank you a lot for any help. Edited June 14, 2016 by nikivi
deanishe Posted June 14, 2016 Posted June 14, 2016 In the case of a Run Script Action, the {query} of the following element is whatever the script prints to STDOUT. In this case, ping's output + Online/Offline. Post Notification treats {query} differently in each field. Title shows only the first line. Text shows more. If you don't want to see the output of ping, use: ping -o -t 2 google.com > /dev/null
nikivi Posted June 14, 2016 Posted June 14, 2016 Thank you. That makes sense now. Today I learned about /dev/null
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