mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 09:28:38 +00:00
add FlexSpace. A bit refactor structure. Correct loading scripts from preset
This commit is contained in:
parent
11c8d167c0
commit
f08ce7a381
@ -24,10 +24,18 @@
|
||||
B09EB1E4207C082000D5C1E0 /* HapticFeedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = B09EB1E3207C082000D5C1E0 /* HapticFeedback.swift */; };
|
||||
B09EB1E6207C0F8E00D5C1E0 /* MultitouchSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B09EB1E5207C0F8E00D5C1E0 /* MultitouchSupport.framework */; };
|
||||
B0A7E9AA205D6AA400EEF070 /* KeyPress.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */; };
|
||||
B0A8BF9E207B84160086F74D /* weather.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0A8BF9D207B84160086F74D /* weather.scpt */; };
|
||||
B0B17431207D6B590004B740 /* PlaySmart.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0B17427207D6B580004B740 /* PlaySmart.scpt */; };
|
||||
B0B17432207D6B590004B740 /* Weather.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0B17428207D6B580004B740 /* Weather.scpt */; };
|
||||
B0B17433207D6B590004B740 /* Finder.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0B17429207D6B580004B740 /* Finder.scpt */; };
|
||||
B0B17434207D6B590004B740 /* Battery.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0B1742A207D6B580004B740 /* Battery.scpt */; };
|
||||
B0B17435207D6B590004B740 /* Spotify.next.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0B1742B207D6B590004B740 /* Spotify.next.scpt */; };
|
||||
B0B17436207D6B590004B740 /* iTunes.next.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0B1742C207D6B590004B740 /* iTunes.next.scpt */; };
|
||||
B0B17437207D6B590004B740 /* Spotify.nowPlaying.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0B1742D207D6B590004B740 /* Spotify.nowPlaying.scpt */; };
|
||||
B0B17438207D6B590004B740 /* Vox.next.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0B1742E207D6B590004B740 /* Vox.next.scpt */; };
|
||||
B0B17439207D6B590004B740 /* Vox.nowPlaying.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0B1742F207D6B590004B740 /* Vox.nowPlaying.scpt */; };
|
||||
B0B1743A207D6B590004B740 /* iTunes.nowPlaying.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0B17430207D6B590004B740 /* iTunes.nowPlaying.scpt */; };
|
||||
B0C1CFCA205C97D30021C862 /* WindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C1CFC9205C97D30021C862 /* WindowController.swift */; };
|
||||
B0F8771A207AC1EA00D6E430 /* TouchBarSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */; };
|
||||
B0F8771D207AD35400D6E430 /* battery.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0F8771C207AD35400D6E430 /* battery.scpt */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@ -75,11 +83,19 @@
|
||||
B09EB1E3207C082000D5C1E0 /* HapticFeedback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HapticFeedback.swift; sourceTree = "<group>"; };
|
||||
B09EB1E5207C0F8E00D5C1E0 /* MultitouchSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MultitouchSupport.framework; path = ../../../../../System/Library/PrivateFrameworks/MultitouchSupport.framework; sourceTree = "<group>"; };
|
||||
B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyPress.swift; sourceTree = "<group>"; };
|
||||
B0A8BF9D207B84160086F74D /* weather.scpt */ = {isa = PBXFileReference; lastKnownFileType = text; path = weather.scpt; sourceTree = "<group>"; };
|
||||
B0B17427207D6B580004B740 /* PlaySmart.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = PlaySmart.scpt; sourceTree = "<group>"; };
|
||||
B0B17428207D6B580004B740 /* Weather.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Weather.scpt; sourceTree = "<group>"; };
|
||||
B0B17429207D6B580004B740 /* Finder.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Finder.scpt; sourceTree = "<group>"; };
|
||||
B0B1742A207D6B580004B740 /* Battery.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Battery.scpt; sourceTree = "<group>"; };
|
||||
B0B1742B207D6B590004B740 /* Spotify.next.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Spotify.next.scpt; sourceTree = "<group>"; };
|
||||
B0B1742C207D6B590004B740 /* iTunes.next.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = iTunes.next.scpt; sourceTree = "<group>"; };
|
||||
B0B1742D207D6B590004B740 /* Spotify.nowPlaying.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Spotify.nowPlaying.scpt; sourceTree = "<group>"; };
|
||||
B0B1742E207D6B590004B740 /* Vox.next.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Vox.next.scpt; sourceTree = "<group>"; };
|
||||
B0B1742F207D6B590004B740 /* Vox.nowPlaying.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Vox.nowPlaying.scpt; sourceTree = "<group>"; };
|
||||
B0B17430207D6B590004B740 /* iTunes.nowPlaying.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = iTunes.nowPlaying.scpt; sourceTree = "<group>"; };
|
||||
B0C1CFC9205C97D30021C862 /* WindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowController.swift; sourceTree = "<group>"; };
|
||||
B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TouchBarSupport.m; sourceTree = "<group>"; };
|
||||
B0F8771B207AC92700D6E430 /* TouchBarSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchBarSupport.h; sourceTree = "<group>"; };
|
||||
B0F8771C207AD35400D6E430 /* battery.scpt */ = {isa = PBXFileReference; lastKnownFileType = text; path = battery.scpt; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -144,8 +160,8 @@
|
||||
B082B251205C7D8000BC04DC /* MTMR */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B059D629205E13E5006E6B86 /* TouchBarPrivateApi.h */,
|
||||
B059D62A205F0E7D006E6B86 /* TouchBarPrivateApi-Bridging.h */,
|
||||
B0B1743B207D6ED40004B740 /* CBridge */,
|
||||
B0B17426207D6AFE0004B740 /* AppleScripts */,
|
||||
B082B252205C7D8000BC04DC /* AppDelegate.swift */,
|
||||
B082B254205C7D8000BC04DC /* ViewController.swift */,
|
||||
B082B256205C7D8000BC04DC /* Assets.xcassets */,
|
||||
@ -154,16 +170,12 @@
|
||||
36C2ECD8207B74B4003CDA33 /* AppleScriptTouchBarItem.swift */,
|
||||
36C2ECD6207B6DAE003CDA33 /* TimeTouchBarItem.swift */,
|
||||
B059D621205E03F5006E6B86 /* TouchBarController.swift */,
|
||||
36C2ECDA207C3FE7003CDA33 /* ItemsParsing.swift */,
|
||||
B0C1CFC9205C97D30021C862 /* WindowController.swift */,
|
||||
B082B258205C7D8000BC04DC /* Main.storyboard */,
|
||||
B082B25B205C7D8000BC04DC /* Info.plist */,
|
||||
B082B25C205C7D8000BC04DC /* MTMR.entitlements */,
|
||||
B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */,
|
||||
B0F8771B207AC92700D6E430 /* TouchBarSupport.h */,
|
||||
B0F8771C207AD35400D6E430 /* battery.scpt */,
|
||||
B0A8BF9D207B84160086F74D /* weather.scpt */,
|
||||
B09EB1E3207C082000D5C1E0 /* HapticFeedback.swift */,
|
||||
36C2ECDA207C3FE7003CDA33 /* ItemsParsing.swift */,
|
||||
36C2ECDF207CB1B0003CDA33 /* defaultPreset.json */,
|
||||
);
|
||||
path = MTMR;
|
||||
@ -187,6 +199,34 @@
|
||||
path = MTMRUITests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
B0B17426207D6AFE0004B740 /* AppleScripts */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B0B1742A207D6B580004B740 /* Battery.scpt */,
|
||||
B0B17429207D6B580004B740 /* Finder.scpt */,
|
||||
B0B1742C207D6B590004B740 /* iTunes.next.scpt */,
|
||||
B0B17430207D6B590004B740 /* iTunes.nowPlaying.scpt */,
|
||||
B0B17427207D6B580004B740 /* PlaySmart.scpt */,
|
||||
B0B1742B207D6B590004B740 /* Spotify.next.scpt */,
|
||||
B0B1742D207D6B590004B740 /* Spotify.nowPlaying.scpt */,
|
||||
B0B1742E207D6B590004B740 /* Vox.next.scpt */,
|
||||
B0B1742F207D6B590004B740 /* Vox.nowPlaying.scpt */,
|
||||
B0B17428207D6B580004B740 /* Weather.scpt */,
|
||||
);
|
||||
path = AppleScripts;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
B0B1743B207D6ED40004B740 /* CBridge */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B059D629205E13E5006E6B86 /* TouchBarPrivateApi.h */,
|
||||
B059D62A205F0E7D006E6B86 /* TouchBarPrivateApi-Bridging.h */,
|
||||
B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */,
|
||||
B0F8771B207AC92700D6E430 /* TouchBarSupport.h */,
|
||||
);
|
||||
path = CBridge;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
@ -299,11 +339,19 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
B0A8BF9E207B84160086F74D /* weather.scpt in Resources */,
|
||||
B0B17434207D6B590004B740 /* Battery.scpt in Resources */,
|
||||
B0B1743A207D6B590004B740 /* iTunes.nowPlaying.scpt in Resources */,
|
||||
B082B257205C7D8000BC04DC /* Assets.xcassets in Resources */,
|
||||
B0B17437207D6B590004B740 /* Spotify.nowPlaying.scpt in Resources */,
|
||||
B0B17436207D6B590004B740 /* iTunes.next.scpt in Resources */,
|
||||
B082B25A205C7D8000BC04DC /* Main.storyboard in Resources */,
|
||||
B0B17435207D6B590004B740 /* Spotify.next.scpt in Resources */,
|
||||
B0B17433207D6B590004B740 /* Finder.scpt in Resources */,
|
||||
B0B17439207D6B590004B740 /* Vox.nowPlaying.scpt in Resources */,
|
||||
B0B17438207D6B590004B740 /* Vox.next.scpt in Resources */,
|
||||
36C2ECE0207CB1B0003CDA33 /* defaultPreset.json in Resources */,
|
||||
B0F8771D207AD35400D6E430 /* battery.scpt in Resources */,
|
||||
B0B17432207D6B590004B740 /* Weather.scpt in Resources */,
|
||||
B0B17431207D6B590004B740 /* PlaySmart.scpt in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -511,7 +559,7 @@
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMR;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "MTMR/TouchBarPrivateApi-Bridging.h";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h";
|
||||
SWIFT_VERSION = 4.0;
|
||||
};
|
||||
name = Debug;
|
||||
@ -531,7 +579,7 @@
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMR;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "MTMR/TouchBarPrivateApi-Bridging.h";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h";
|
||||
SWIFT_VERSION = 4.0;
|
||||
};
|
||||
name = Release;
|
||||
|
||||
@ -3,27 +3,27 @@ set percent to word 6 of theList's item 2
|
||||
set charge to word 7 of theList's item 2
|
||||
|
||||
if (charge = "charging") then
|
||||
set iconC to "⚡️"
|
||||
set iconC to "⚡️"
|
||||
else
|
||||
set iconC to ""
|
||||
set iconC to ""
|
||||
end if
|
||||
|
||||
set remainingRaw to my split(theList's item 2, " ")
|
||||
set remainingTime to remainingRaw's item 5
|
||||
|
||||
if (remainingTime = "(no") then
|
||||
set strTime to " (?)"
|
||||
set strTime to " (?)"
|
||||
else if (remainingTime = "0:00") then
|
||||
set strTime to ""
|
||||
set strTime to ""
|
||||
else
|
||||
set strTime to " (" & remainingTime & ")"
|
||||
set strTime to " (" & remainingTime & ")"
|
||||
end if
|
||||
|
||||
return iconC & percent & "%" & strTime
|
||||
|
||||
to split(someText, delimiter)
|
||||
set AppleScript's text item delimiters to delimiter
|
||||
set someText to someText's text items
|
||||
set AppleScript's text item delimiters to {""}
|
||||
return someText
|
||||
set AppleScript's text item delimiters to delimiter
|
||||
set someText to someText's text items
|
||||
set AppleScript's text item delimiters to {""}
|
||||
return someText
|
||||
end split
|
||||
5
MTMR/AppleScripts/Finder.scpt
Normal file
5
MTMR/AppleScripts/Finder.scpt
Normal file
@ -0,0 +1,5 @@
|
||||
tell application "Finder"
|
||||
make new Finder window
|
||||
set target of front window to path to home folder as string
|
||||
activate
|
||||
end tell
|
||||
11
MTMR/AppleScripts/PlaySmart.scpt
Normal file
11
MTMR/AppleScripts/PlaySmart.scpt
Normal file
@ -0,0 +1,11 @@
|
||||
if application "iTunes" is running then
|
||||
tell application "iTunes" to playpause
|
||||
end if
|
||||
|
||||
if application "Spotify" is running then
|
||||
tell application "Spotify" to playpause
|
||||
end if
|
||||
|
||||
if application "VOX" is running then
|
||||
tell application "VOX" to playpause
|
||||
end if
|
||||
7
MTMR/AppleScripts/Spotify.next.scpt
Normal file
7
MTMR/AppleScripts/Spotify.next.scpt
Normal file
@ -0,0 +1,7 @@
|
||||
if application "Spotify" is running then
|
||||
tell application "Spotify"
|
||||
if player state is playing then
|
||||
next track
|
||||
end if
|
||||
end tell
|
||||
end if
|
||||
10
MTMR/AppleScripts/Spotify.nowPlaying.scpt
Normal file
10
MTMR/AppleScripts/Spotify.nowPlaying.scpt
Normal file
@ -0,0 +1,10 @@
|
||||
if application "Spotify" is running then
|
||||
tell application "Spotify"
|
||||
if player state is playing then
|
||||
return (get artist of current track) & " – " & (get name of current track)
|
||||
else
|
||||
return ""
|
||||
end if
|
||||
end tell
|
||||
end if
|
||||
return ""
|
||||
7
MTMR/AppleScripts/Vox.next.scpt
Normal file
7
MTMR/AppleScripts/Vox.next.scpt
Normal file
@ -0,0 +1,7 @@
|
||||
if application "VOX" is running then
|
||||
tell application "VOX"
|
||||
if player state is 1 then
|
||||
next
|
||||
end if
|
||||
end tell
|
||||
end if
|
||||
10
MTMR/AppleScripts/Vox.nowPlaying.scpt
Normal file
10
MTMR/AppleScripts/Vox.nowPlaying.scpt
Normal file
@ -0,0 +1,10 @@
|
||||
if application "VOX" is running then
|
||||
tell application "VOX"
|
||||
if player state is 1 then
|
||||
return (get artist) & " – " & (get track)
|
||||
else
|
||||
return ""
|
||||
end if
|
||||
end tell
|
||||
end if
|
||||
return ""
|
||||
32
MTMR/AppleScripts/Weather.scpt
Normal file
32
MTMR/AppleScripts/Weather.scpt
Normal file
@ -0,0 +1,32 @@
|
||||
# This script requires two libs. Download them:
|
||||
# https://itunes.apple.com/ru/app/json-helper-for-applescript/id453114608?l=en&mt=12
|
||||
# https://itunes.apple.com/ru/app/location-helper-for-applescript/id488536386?mt=12
|
||||
tell application "Location Helper"
|
||||
set clocation_coords to get location coordinates
|
||||
tell application "JSON Helper"
|
||||
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"
|
||||
set temp to temp of main of weather as string
|
||||
set cond_icon to icon of item 1 of weather of weather as string
|
||||
if cond_icon is in ["01d", "01n"] then
|
||||
set cond to "☀️"
|
||||
else if cond_icon is in ["02d", "02n"] then
|
||||
set cond to "⛅️"
|
||||
else if cond_icon is in ["03d", "03n", "04d", "04n"] then
|
||||
set cond to "☁️"
|
||||
else if cond_icon is in ["09d", "09n"] then
|
||||
set cond to "🌧"
|
||||
else if cond_icon is in ["10d", "10n"] then
|
||||
set cond to "🌦"
|
||||
else if cond_icon is in ["11d", "11n"] then
|
||||
set cond to "🌩"
|
||||
else if cond_icon is in ["13d", "13n"] then
|
||||
set cond to "❄️"
|
||||
else if cond_icon is in ["50d", "50n"] then
|
||||
set cond to "🌫"
|
||||
else
|
||||
set cond to ""
|
||||
end if
|
||||
set temp_round to round (temp * 1.0)
|
||||
return cond & " " & temp_round & "°C"
|
||||
end tell
|
||||
end tell
|
||||
7
MTMR/AppleScripts/iTunes.next.scpt
Normal file
7
MTMR/AppleScripts/iTunes.next.scpt
Normal file
@ -0,0 +1,7 @@
|
||||
if application "iTunes" is running then
|
||||
tell application "iTunes"
|
||||
if player state is playing then
|
||||
next track
|
||||
end if
|
||||
end tell
|
||||
end if
|
||||
10
MTMR/AppleScripts/iTunes.nowPlaying.scpt
Normal file
10
MTMR/AppleScripts/iTunes.nowPlaying.scpt
Normal file
@ -0,0 +1,10 @@
|
||||
if application "iTunes" is running then
|
||||
tell application "iTunes"
|
||||
if player state is playing then
|
||||
return (get artist of current track) & " – " & (get name of current track)
|
||||
else
|
||||
return ""
|
||||
end if
|
||||
end tell
|
||||
end if
|
||||
return ""
|
||||
@ -53,7 +53,7 @@ class SupportedTypesHolder {
|
||||
enum CodingKeys: String, CodingKey { case refreshInterval }
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval)
|
||||
let scriptURL = Bundle.main.url(forResource: "weather", withExtension: "scpt")!
|
||||
let scriptURL = Bundle.main.url(forResource: "Weather", withExtension: "scpt")!
|
||||
let item = ItemType.appleScriptTitledButton(source: try! String(contentsOf: scriptURL), refreshInterval: interval ?? 1800.0)
|
||||
return (item: item, action: .none)
|
||||
},
|
||||
@ -61,7 +61,8 @@ class SupportedTypesHolder {
|
||||
enum CodingKeys: String, CodingKey { case refreshInterval }
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval)
|
||||
let scriptURL = Bundle.main.url(forResource: "battery", withExtension: "scpt")!
|
||||
let scriptURL = Bundle.main.url(forResource: "Battery", withExtension: "scpt")!
|
||||
print(try! String(contentsOf: scriptURL))
|
||||
let item = ItemType.appleScriptTitledButton(source: try! String(contentsOf: scriptURL), refreshInterval: interval ?? 1800.0)
|
||||
return (item: item, action: .none)
|
||||
},
|
||||
@ -91,6 +92,7 @@ enum ItemType: Decodable {
|
||||
case staticButton(title: String)
|
||||
case appleScriptTitledButton(source: String, refreshInterval: Double)
|
||||
case timeButton(formatTemplate: String)
|
||||
case flexSpace()
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case type
|
||||
@ -104,6 +106,7 @@ enum ItemType: Decodable {
|
||||
case staticButton
|
||||
case appleScriptTitledButton
|
||||
case timeButton
|
||||
case flexSpace
|
||||
}
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
@ -113,13 +116,15 @@ enum ItemType: Decodable {
|
||||
case .appleScriptTitledButton:
|
||||
let source = try container.decode(String.self, forKey: .titleAppleScript)
|
||||
let interval = try container.decode(Double.self, forKey: .refreshInterval)
|
||||
self = .appleScriptTitledButton(source: source, refreshInterval: interval)
|
||||
self = .appleScriptTitledButton(source: try String(contentsOfFile: source), refreshInterval: interval)
|
||||
case .staticButton:
|
||||
let title = try container.decode(String.self, forKey: .title)
|
||||
self = .staticButton(title: title)
|
||||
case .timeButton:
|
||||
let template = try container.decodeIfPresent(String.self, forKey: .formatTemplate) ?? "HH:mm"
|
||||
self = .timeButton(formatTemplate: template)
|
||||
case .flexSpace:
|
||||
self = .flexSpace()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -173,7 +178,9 @@ enum ActionType: Decodable {
|
||||
extension ItemType: Equatable {}
|
||||
func ==(lhs: ItemType, rhs: ItemType) -> Bool {
|
||||
switch (lhs, rhs) {
|
||||
case let (.staticButton(a), .staticButton(b)):
|
||||
case let (.staticButton(a), .staticButton(b)):
|
||||
return a == b
|
||||
case let (.flexSpace(a), .flexSpace(b)):
|
||||
return a == b
|
||||
case let (.appleScriptTitledButton(a, b), .appleScriptTitledButton(c, d)):
|
||||
return a == c && b == d
|
||||
|
||||
@ -23,6 +23,8 @@ extension ItemType {
|
||||
return "com.toxblh.mtmr.appleScriptButton."
|
||||
case .timeButton(formatTemplate: _):
|
||||
return "com.toxblh.mtmr.timeButton."
|
||||
case .flexSpace():
|
||||
return "NSTouchBarItem.Identifier.flexibleSpace"
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +63,9 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
|
||||
for item in jsonItems {
|
||||
let identifierString = item.type.identifierBase.appending(UUID().uuidString)
|
||||
let identifier = NSTouchBarItem.Identifier(identifierString)
|
||||
let identifier = item.type == ItemType.flexSpace()
|
||||
? NSTouchBarItem.Identifier.flexibleSpace
|
||||
: NSTouchBarItem.Identifier(identifierString)
|
||||
items[identifier] = item
|
||||
touchBar.defaultItemIdentifiers += [identifier]
|
||||
}
|
||||
@ -100,6 +104,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
barItem = AppleScriptTouchBarItem(identifier: identifier, appleScript: source, interval: interval)
|
||||
case .timeButton(formatTemplate: let template):
|
||||
barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template)
|
||||
case .flexSpace:
|
||||
barItem = nil
|
||||
}
|
||||
for parameter in item.additionalParameters {
|
||||
if case .width(let value) = parameter, let widthBarItem = barItem as? CanSetWidth {
|
||||
|
||||
@ -1,15 +1,22 @@
|
||||
[
|
||||
{ "type": "escape" },
|
||||
{ "type": "exitTouchbar" },
|
||||
{ "type": "brightnessDown" },
|
||||
{ "type": "brightnessUp" },
|
||||
{ "type": "volumeDown", "width": 44 },
|
||||
{ "type": "volumeUp", "width": 44 },
|
||||
{ "type": "previous" },
|
||||
{ "type": "play" },
|
||||
{ "type": "next" },
|
||||
{ "type": "weather", "refreshInterval": 1800 },
|
||||
{ "type": "sleep" },
|
||||
{ "type": "battery" },
|
||||
{ "type": "timeButton" },
|
||||
{ "type": "escape" },
|
||||
{ "type": "exitTouchbar" },
|
||||
{ "type": "brightnessDown" },
|
||||
{
|
||||
"type": "staticButton",
|
||||
"title": "🔆",
|
||||
"action": "keyPress",
|
||||
"keycode": 113,
|
||||
"width": 36,
|
||||
},
|
||||
{ "type": "flexSpace" },
|
||||
{ "type": "volumeDown", "width": 44 },
|
||||
{ "type": "volumeUp", "width": 44 },
|
||||
{ "type": "previous" },
|
||||
{ "type": "play" },
|
||||
{ "type": "next" },
|
||||
{ "type": "weather", "refreshInterval": 1800 },
|
||||
{ "type": "sleep" },
|
||||
{ "type": "battery" },
|
||||
{ "type": "timeButton" },
|
||||
]
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
# This script requires two libs. Download them:
|
||||
# https://itunes.apple.com/ru/app/json-helper-for-applescript/id453114608?l=en&mt=12
|
||||
# https://itunes.apple.com/ru/app/location-helper-for-applescript/id488536386?mt=12
|
||||
tell application "Location Helper"
|
||||
set clocation_coords to get location coordinates
|
||||
tell application "JSON Helper"
|
||||
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"
|
||||
set temp to temp of main of weather as string
|
||||
set cond_icon to icon of item 1 of weather of weather as string
|
||||
if cond_icon is in ["01d", "01n"] then
|
||||
set cond to "☀️"
|
||||
else if cond_icon is in ["02d", "02n"] then
|
||||
set cond to "⛅️"
|
||||
else if cond_icon is in ["03d", "03n", "04d", "04n"] then
|
||||
set cond to "☁️"
|
||||
else if cond_icon is in ["09d", "09n"] then
|
||||
set cond to "🌧"
|
||||
else if cond_icon is in ["10d", "10n"] then
|
||||
set cond to "🌦"
|
||||
else if cond_icon is in ["11d", "11n"] then
|
||||
set cond to "🌩"
|
||||
else if cond_icon is in ["13d", "13n"] then
|
||||
set cond to "❄️"
|
||||
else if cond_icon is in ["50d", "50n"] then
|
||||
set cond to "🌫"
|
||||
else
|
||||
set cond to ""
|
||||
end if
|
||||
set temp_round to round (temp * 1.0)
|
||||
return cond & " " & temp_round & "°C"
|
||||
end tell
|
||||
end tell
|
||||
Loading…
Reference in New Issue
Block a user