forked from samuelmeuli/glance
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppleScriptPreview.swift
More file actions
25 lines (24 loc) · 903 Bytes
/
AppleScriptPreview.swift
File metadata and controls
25 lines (24 loc) · 903 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
import SwiftExec
/// View controller for previewing AppleScript files:
///
/// - `.applescript`: AppleScript text file (can be read directly)
/// - `.scpt`: AppleScript binary (needs to be decompiled)
/// - `.scptd`: AppleScript bundle (includes a binary, which needs to be decompiled)
///
/// The class extends `CodePreview` so syntax highlighting is applied after the script's content has
/// been determined.
///
// TODO: Scripts can also be written in JavaScript (JXA). This language needs to be detected and
// passed to Chroma to get correct syntax highlighting.
class AppleScriptPreview: CodePreview {
override func getSource(file: File) throws -> String {
if file.url.pathExtension == "scpt" || file.url.pathExtension == "scptd" {
let result = try exec(
program: "/usr/bin/osadecompile",
arguments: [file.path]
)
return result.stdout ?? ""
}
return try file.read()
}
}