In both cases, we just need to create a shell script, put it into appropriate directory (in case of Argos, it’s
~/.config/argos/ and in case of BitBar, we define it during the installation or first run) and then app displays our data automatically. We can also set refresh rate. E.g. if we want our script to be executed every 60 seconds, we can name it
script.60s.sh. We can also create more advanced scripts and more details can be found in BitBar and Argos documentation.
In my case, I wanted to create a script, which reads
CAQI (Common Air Quality Index) in my current location based on Airly sensors. Airly provides nice API, which we can use in our projects. Please remember that most of the sensors are located in Poland.
On my Ubuntu Linux with Gnome 3, I created a new script in the following path:
For a BitBar script location could be different. Both for BitBar and Argos follow the same naming convention.
My script looks as follows:
#!/usr/bin/env bash CAQI=$(curl -s -X GET --header 'Accept: application/json' --header 'apikey: YOUR_API_KEY' \ 'https://airapi.airly.eu/v1/nearestSensor/measurements?latitude=YOUR_LATITUDE&longitude=YOUR_LONGITUDE&maxDistance=1000' \ | jq .airQualityIndex | cut -f1 -d".") MSG="Unknown" case 1 in $(($CAQI <= 25))) MSG="Great!";; $(($CAQI <= 50))) MSG="Good!";; $(($CAQI <= 75))) MSG="Medium";; $(($CAQI <= 100))) MSG="Bad";; $(($CAQI >= 101))) MSG="Very Bad";; esac echo "CAQI: $CAQI ($MSG)"
It works fine on Linux. The only requirement is to install jq. For macOS, I needed to change
/usr/local/bin/jq to make it work. I gathered information about air quality level from this website: https://www.airqualitynow.eu/pl/about_indices_definition.php [PL]. Of course, we need to replace
API_KEY with our api key, which we can get from https://developer.airly.eu/ website as well as
YOUR_LONGITUDE with coordinates of our location. It can be static location in our city. We can get them e.g. from Google Maps.
As a result, we have beautiful text in our top panel:
This screenshot was taken on Ubuntu Linux with Gnome 3. On macOS it works the same (I checked it).