Jump to content

Simple Internet Test

Recommended Posts

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!

Link to comment

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"
    echo "Offline"

Put that in a Run Script Action (Language = /bin/bash) and connect it to a Post Notification or Large Type Output.

Link to comment

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 by nikivi
Link to comment

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

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