mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 17:38:38 +00:00
Merge pull request #92 from ReDetection/compiled-applescript
Support compiled applescript files
This commit is contained in:
commit
ea573882a0
@ -63,13 +63,6 @@ class AppleScriptTouchBarItem: CustomButtonTouchBarItem {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SourceProtocol {
|
|
||||||
var appleScript: NSAppleScript? {
|
|
||||||
guard let source = self.string else { return nil }
|
|
||||||
return NSAppleScript(source: source)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension DispatchQueue {
|
extension DispatchQueue {
|
||||||
static let appleScriptQueue = DispatchQueue(label: "mtmr.applescript")
|
static let appleScriptQueue = DispatchQueue(label: "mtmr.applescript")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -413,6 +413,7 @@ protocol SourceProtocol {
|
|||||||
var data: Data? { get }
|
var data: Data? { get }
|
||||||
var string: String? { get }
|
var string: String? { get }
|
||||||
var image: NSImage? { get }
|
var image: NSImage? { get }
|
||||||
|
var appleScript: NSAppleScript? { get }
|
||||||
}
|
}
|
||||||
struct Source: Decodable, SourceProtocol {
|
struct Source: Decodable, SourceProtocol {
|
||||||
let filePath: String?
|
let filePath: String?
|
||||||
@ -434,6 +435,9 @@ struct Source: Decodable, SourceProtocol {
|
|||||||
var image: NSImage? {
|
var image: NSImage? {
|
||||||
return data?.image
|
return data?.image
|
||||||
}
|
}
|
||||||
|
var appleScript: NSAppleScript? {
|
||||||
|
return filePath?.fileURL.appleScript ?? self.string?.appleScript
|
||||||
|
}
|
||||||
|
|
||||||
private init(filePath: String?, base64: String?, inline: String?) {
|
private init(filePath: String?, base64: String?, inline: String?) {
|
||||||
self.filePath = filePath
|
self.filePath = filePath
|
||||||
@ -454,6 +458,9 @@ extension NSImage: SourceProtocol {
|
|||||||
var image: NSImage? {
|
var image: NSImage? {
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
var appleScript: NSAppleScript? {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension String {
|
extension String {
|
||||||
@ -484,3 +491,19 @@ enum Align: String, Decodable {
|
|||||||
case center
|
case center
|
||||||
case right
|
case right
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension String {
|
||||||
|
var fileURL: URL {
|
||||||
|
return URL(fileURLWithPath: self)
|
||||||
|
}
|
||||||
|
var appleScript: NSAppleScript? {
|
||||||
|
return NSAppleScript(source: self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension URL {
|
||||||
|
var appleScript: NSAppleScript? {
|
||||||
|
guard FileManager.default.fileExists(atPath: self.path) else { return nil }
|
||||||
|
return NSAppleScript(contentsOf: self, error: nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user