I agree that pretty much any solution you can get for the command line would have to rely on AppleScript. And your solution will work. However, rather than scripting System Events, which depends on UI events (actually moving your mouse and clicking) it's a much cleaner approach to script the application's window directly.
This way, if you move your mouse while the script is executing, it won't affect it. For minimizing all Firefox windows you could do something like:
tell application "Firefox" to set miniaturized of every window to true
The property is called miniaturized
for Firefox and most OS X applications, but some third-party apps, like Google Chrome, call the property minimized
, so if one doesn't work, the other should. This functionality is part of the Standard Suite that pretty much every AppleScript-able application has.
For applications that don't support AppleScript at all, you can fall back to your approach and use System Events to access the windows belonging to the application's specific process running on your machine.
If I were you, though, I'd try to rely on the application to minimize itself rather than through System Events where possible, as this will be much more reliable.
Simplest solution is ansiweather
which you can install with brew
. The result looks like .
If you want to write you own command/function it's not that difficult. If the output from the online location is in json, or something similar. You can use jq
to parse json, and only print what you need.
curl -s http://ip-api.com/json | jq -Cr .
Read the manual page of jq
to learn how to use it.
I tried the API you're using above, that's not gonna help your case. Find some other one that replies in JSON. For example:
curl -s 'api.openweathermap.org/data/2.5/weather?q={CITY,COUNTRY_CODE}&APPID={GET_YOUR_API_KEY}' | jq -C '.name? .weather?.main?'
I haven't tested it personally, because you have to make an account to make a call, but you get the idea.
Comment if you get lost.
Best Answer
So
does the trick.