forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpers.swift
More file actions
27 lines (25 loc) · 766 Bytes
/
Helpers.swift
File metadata and controls
27 lines (25 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import Foundation
extension FileManager {
func fileIsDirectory(atPath path: String) -> Bool {
var isDirectory: ObjCBool = false
let exists = fileExists(atPath: path, isDirectory: &isDirectory)
return isDirectory.boolValue && exists
}
}
@discardableResult
func runAppleScript(_ appleScript: String) async throws -> String? {
let task = Process()
task.launchPath = "/usr/bin/osascript"
task.arguments = ["-e", appleScript]
let outpipe = Pipe()
task.standardOutput = outpipe
try task.run()
await Task.yield()
task.waitUntilExit()
if let data = try outpipe.fileHandleForReading.readToEnd(),
let content = String(data: data, encoding: .utf8)
{
return content
}
return nil
}