mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-10-31 10:28:36 +00:00
add FlexSpace. A bit refactor structure. Correct loading scripts from preset
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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 ""
|
||||
@@ -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
|
||||
@@ -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 ""
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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 ""
|
||||
+11
-4
@@ -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 {
|
||||
|
||||
+20
-13
@@ -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
|
||||
Reference in New Issue
Block a user