Created
March 12, 2025 00:42
-
-
Save ghall89/ad65bd2b923cae374688fe73d3e639ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import AppleScriptObjC | |
| import Foundation | |
| enum AppleScriptError: Error { | |
| case scriptCompilationFailed | |
| case executionFailed(String) | |
| } | |
| func runAppleScript(script: String) throws -> String? { | |
| var result: String? | |
| var error: NSDictionary? | |
| guard let appleScript = NSAppleScript(source: script) else { | |
| throw AppleScriptError.scriptCompilationFailed | |
| } | |
| result = appleScript.executeAndReturnError(&error).stringValue | |
| if let error = error { | |
| throw AppleScriptError.executionFailed(error.description) | |
| } | |
| return result | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment