Last active
April 6, 2018 00:59
-
-
Save rjocoleman/ef9ce41846e55c9e62549e33b2500b0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script requires a free library. Download and run once: | |
# https://itunes.apple.com/nz/app/json-helper-for-applescript/id453114608?l=en&mt=12 | |
# Get a free DarkSky API key from here: https://darksky.net/dev/ | |
tell application "Location Helper" | |
## set your DarkSky API key | |
set apiKey to "API_KEY" | |
## Units can be "us" or "si" - see https://darksky.net/dev/docs | |
set units to "si" | |
# Version 1 | |
# requires location helper | |
# install and run once - http://www.mousedown.net/mouseware/LocationHelper.html | |
# change the above to - tell application "Location Helper" | |
set clocation_coords to get location coordinates | |
set latLon to item 1 of clocation_coords & "," & item 2 of clocation_coords | |
# Version 2 | |
# locateme is required - http://iharder.sourceforge.net/current/macosx/locateme/ | |
# this can be installed via homebrew - brew install locateme | |
# set latLon to do shell script "/usr/local/bin/locateme -f '{LAT},{LON}'" | |
# change the above to - tell application "JSON Helper" | |
set weather to fetch JSON from ("https://api.darksky.net/forecast/" & apiKey & "/" & latLon & "?exclude=minutely,hourly,daily,alerts,flags&units=" & units) | |
set temperature to temperature of currently of weather | |
set weatherStatus to icon of currently of weather | |
end tell | |
if weatherStatus is equal to "clear-day" then | |
set myIcon to "☀️" | |
else if weatherStatus is equal to "clear-night" then | |
set myIcon to "🌙" | |
else if weatherStatus is equal to "partly-cloudy-day" or weatherStatus is equal to "partly-cloudy-night" then | |
set myIcon to "⛅️" | |
else if weatherStatus is equal to "partly-cloudy-night" then | |
set myIcon to "☁️🌙" | |
else if weatherStatus is equal to "cloudy" then | |
set myIcon to "☁️" | |
else if weatherStatus is equal to "rain" then | |
set myIcon to "🌧" | |
else if weatherStatus is equal to "sleet" then | |
set myIcon to "⛈" | |
else if weatherStatus is equal to "fog" then | |
set myIcon to "🌫️" | |
else if weatherStatus is equal to "wind" then | |
set myIcon to "🌀" | |
else if weatherStatus is equal to "snow" then | |
set myIcon to "❄️" | |
else | |
set myIcon to weatherStatus | |
end if | |
return myIcon & (round (temperature)) & "°" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "Location Helper" | |
## Units can be "us12" or "si12" - work it out from going to the website | |
set units to "si12" | |
# Version 1 | |
# requires location helper | |
# install and run once - http://www.mousedown.net/mouseware/LocationHelper.html | |
# change the above to - tell application "Location Helper" | |
set clocation_coords to get location coordinates | |
set latLon to item 1 of clocation_coords & "," & item 2 of clocation_coords | |
# Version 2 | |
# locateme is required - http://iharder.sourceforge.net/current/macosx/locateme/ | |
# this can be installed via homebrew - brew install locateme | |
# set latLon to do shell script "/usr/local/bin/locateme -f '{LAT},{LON}'" | |
# change the above to - tell application "JSON Helper" | |
open location "https://darksky.net/forecast/" & latLon & "/" & units & "/en" | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment