Skip to content

Commit ab4aef4

Browse files
committed
added weather
1 parent e3f5da0 commit ab4aef4

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

MTMR.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
B082B266205C7D8000BC04DC /* MTMRTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B082B265205C7D8000BC04DC /* MTMRTests.swift */; };
2020
B082B271205C7D8000BC04DC /* MTMRUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B082B270205C7D8000BC04DC /* MTMRUITests.swift */; };
2121
B0A7E9AA205D6AA400EEF070 /* KeyPress.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */; };
22+
B0A8BF9E207B84160086F74D /* weather.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0A8BF9D207B84160086F74D /* weather.scpt */; };
2223
B0C1CFCA205C97D30021C862 /* WindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C1CFC9205C97D30021C862 /* WindowController.swift */; };
2324
B0F8771A207AC1EA00D6E430 /* TouchBarSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */; };
2425
B0F8771D207AD35400D6E430 /* battery.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0F8771C207AD35400D6E430 /* battery.scpt */; };
@@ -64,6 +65,7 @@
6465
B082B270205C7D8000BC04DC /* MTMRUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTMRUITests.swift; sourceTree = "<group>"; };
6566
B082B272205C7D8000BC04DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6667
B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyPress.swift; sourceTree = "<group>"; };
68+
B0A8BF9D207B84160086F74D /* weather.scpt */ = {isa = PBXFileReference; lastKnownFileType = text; path = weather.scpt; sourceTree = "<group>"; };
6769
B0C1CFC9205C97D30021C862 /* WindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowController.swift; sourceTree = "<group>"; };
6870
B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TouchBarSupport.m; sourceTree = "<group>"; };
6971
B0F8771B207AC92700D6E430 /* TouchBarSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchBarSupport.h; sourceTree = "<group>"; };
@@ -146,6 +148,7 @@
146148
B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */,
147149
B0F8771B207AC92700D6E430 /* TouchBarSupport.h */,
148150
B0F8771C207AD35400D6E430 /* battery.scpt */,
151+
B0A8BF9D207B84160086F74D /* weather.scpt */,
149152
);
150153
path = MTMR;
151154
sourceTree = "<group>";
@@ -280,6 +283,7 @@
280283
isa = PBXResourcesBuildPhase;
281284
buildActionMask = 2147483647;
282285
files = (
286+
B0A8BF9E207B84160086F74D /* weather.scpt in Resources */,
283287
B082B257205C7D8000BC04DC /* Assets.xcassets in Resources */,
284288
B082B25A205C7D8000BC04DC /* Main.storyboard in Resources */,
285289
B0F8771D207AD35400D6E430 /* battery.scpt in Resources */,

MTMR/TouchBarController.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
7979
return CustomButtonTouchBarItem(identifier: identifier, title: "🔉", HIDKeycode: NX_KEYTYPE_SOUND_DOWN)
8080
case .volumeUp:
8181
return CustomButtonTouchBarItem(identifier: identifier, title: "🔊", HIDKeycode: NX_KEYTYPE_SOUND_UP)
82+
83+
case .weather:
84+
let url = Bundle.main.url(forResource: "weather", withExtension: "scpt")!
85+
let script = try! String.init(contentsOf: url)
86+
return AppleScriptTouchBarItem(identifier: identifier, appleScript: script, interval: 600)
8287

8388
case .prev:
8489
return CustomButtonTouchBarItem(identifier: identifier, title: "", HIDKeycode: NX_KEYTYPE_PREVIOUS)

MTMR/weather.scpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This script requires two libs. Download them:
2+
# https://itunes.apple.com/ru/app/json-helper-for-applescript/id453114608?l=en&mt=12
3+
# https://itunes.apple.com/ru/app/location-helper-for-applescript/id488536386?mt=12
4+
tell application "Location Helper"
5+
set clocation_coords to get location coordinates
6+
tell application "JSON Helper"
7+
set weather to fetch JSON from "http://api.openweathermap.org/data/2.5/weather?lat=" & item 1 of clocation_coords & "&lon=" & item 2 of clocation_coords & "&units=metric&appid=32c4256d09a4c52b38aecddba7a078f6"
8+
set temp to temp of main of weather as string
9+
set cond_icon to icon of item 1 of weather of weather as string
10+
if cond_icon is in ["01d", "01n"] then
11+
set cond to "☀️"
12+
else if cond_icon is in ["02d", "02n"] then
13+
set cond to "⛅️"
14+
else if cond_icon is in ["03d", "03n", "04d", "04n"] then
15+
set cond to "☁️"
16+
else if cond_icon is in ["09d", "09n"] then
17+
set cond to "🌧"
18+
else if cond_icon is in ["10d", "10n"] then
19+
set cond to "🌦"
20+
else if cond_icon is in ["11d", "11n"] then
21+
set cond to "🌩"
22+
else if cond_icon is in ["13d", "13n"] then
23+
set cond to "❄️"
24+
else if cond_icon is in ["50d", "50n"] then
25+
set cond to "🌫"
26+
else
27+
set cond to ""
28+
end if
29+
set temp_round to round (temp * 1.0)
30+
return cond & " " & temp_round & "°C"
31+
end tell
32+
end tell

0 commit comments

Comments
 (0)