Atoll/DynamicIsland/helpers/AppleScriptRunner.swift
Hariharan Mudaliar 1a45d4e7f4 Working Indicators
2025-09-06 19:28:38 +05:30

28 lines
No EOL
767 B
Swift

//
// AppleScriptRunner.swift
// DynamicIsland
//
// Adapted from TheBoringWorker-HUD
// Created by GitHub Copilot on 06/09/25.
//
import Foundation
class AppleScriptRunner {
private init() {}
static func run(script: String) throws -> String {
var error: NSDictionary?
if let scriptObject = NSAppleScript(source: script) {
let output: NSAppleEventDescriptor = scriptObject.executeAndReturnError(&error)
guard error == nil else {
throw AppleScriptError.runtimeError
}
if let outputString = output.stringValue {
return outputString
}
throw AppleScriptError.emptyOutput
}
throw AppleScriptError.initScriptFailed
}
}