mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
31 lines
1.1 KiB
Swift
31 lines
1.1 KiB
Swift
//
|
|
// AppleScriptHelper.swift
|
|
// boringNotch
|
|
//
|
|
// Created by Alexander Greco on 2025-03-29.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
class AppleScriptHelper {
|
|
@discardableResult
|
|
class func execute(_ scriptText: String) async throws -> NSAppleEventDescriptor? {
|
|
try await withCheckedThrowingContinuation { continuation in
|
|
Task.detached(priority: .userInitiated) {
|
|
let script = NSAppleScript(source: scriptText)
|
|
var error: NSDictionary?
|
|
if let descriptor = script?.executeAndReturnError(&error) {
|
|
continuation.resume(returning: descriptor)
|
|
} else if let error = error {
|
|
continuation.resume(throwing: NSError(domain: "AppleScriptError", code: 1, userInfo: error as? [String: Any]))
|
|
} else {
|
|
continuation.resume(throwing: NSError(domain: "AppleScriptError", code: 1, userInfo: [NSLocalizedDescriptionKey: "Unknown error"]))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class func executeVoid(_ scriptText: String) async throws {
|
|
_ = try await execute(scriptText)
|
|
}
|
|
}
|