57 lines · 1.4 KB · Swift
RawDownload
import AppKit enum TerminalApp: String, CaseIterable, Identifiable {    case terminal    case iTerm     var id: String {        self.rawValue    }     var label: String {        switch self {        case .terminal: "Terminal"        case .iTerm: "iTerm"        }    }     var bundleIdentifier: String {        switch self {        case .terminal: "com.apple.Terminal"        case .iTerm: "com.googlecode.iterm2"        }    }     var isInstalled: Bool {        NSWorkspace.shared.urlForApplication(withBundleIdentifier: self.bundleIdentifier) != nil    }     func appleScript(command: String) -> String {        let escaped = Self.escapeForAppleScript(command)        return switch self {        case .terminal:            """            tell application "Terminal"                activate                do script "\(escaped)"            end tell            """        case .iTerm:            """            tell application "iTerm"                activate                set newWindow to (create window with default profile)                tell current session of newWindow                    write text "\(escaped)"                end tell            end tell            """        }    }     static func escapeForAppleScript(_ command: String) -> String {        command            .replacingOccurrences(of: "\\", with: "\\\\")            .replacingOccurrences(of: "\"", with: "\\\"")    }}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t