From 02e7bc26c0eac48e90e34da34fc1a05c4d39fd60 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sat, 25 Jun 2022 10:05:07 +0800 Subject: [PATCH] IME // +NSApplication.shell(). --- Source/Modules/IMEModules/IME.swift | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Source/Modules/IMEModules/IME.swift b/Source/Modules/IMEModules/IME.swift index 390250ae..270b5398 100644 --- a/Source/Modules/IMEModules/IME.swift +++ b/Source/Modules/IMEModules/IME.swift @@ -443,3 +443,29 @@ extension Sequence { .map(\.element) } } + +extension NSApplication { + public static func shell(_ command: String) throws -> String { + let task = Process() + let pipe = Pipe() + + task.standardOutput = pipe + task.standardError = pipe + task.arguments = ["-c", command] + if #available(macOS 10.13, *) { + task.executableURL = URL(fileURLWithPath: "/bin/zsh") + } else { + task.launchPath = "/bin/zsh" + } + task.standardInput = nil + + if #available(macOS 10.13, *) { + try task.run() + } + + let data = pipe.fileHandleForReading.readDataToEndOfFile() + let output = String(data: data, encoding: .utf8)! + + return output + } +}