macOSのスクリーンショットの保存場所を変更するメニュバーエクストラ
Revision | 7be03fdcd6b623db6b07aa993ea2b5370510976a (tree) |
---|---|
Time | 2018-07-01 13:46:30 |
Author | masakih <masakih@user...> |
Commiter | masakih |
Processを使わずUserDefaultsを使うようにした
@@ -43,38 +43,13 @@ class Screenshot { | ||
43 | 43 | |
44 | 44 | private func screencaptureAttribute(_ attr: Attrubute) -> String? { |
45 | 45 | |
46 | - let process = Process() | |
47 | - process.launchPath = "/usr/bin/defaults" | |
48 | - process.arguments = ["read", "com.apple.screencapture", attr.rawValue] | |
49 | - let pipe = Pipe() | |
50 | - process.standardOutput = pipe | |
51 | - process.launch() | |
52 | - process.waitUntilExit() | |
53 | - | |
54 | - let data = pipe.fileHandleForReading.readDataToEndOfFile() | |
55 | - guard let output = String(data: data, encoding: .utf8), | |
56 | - let type = output.components(separatedBy: "\n").first, | |
57 | - process.terminationStatus == 0 else { | |
58 | - | |
59 | - return nil | |
60 | - } | |
61 | - | |
62 | - return type | |
46 | + return UserDefaults(suiteName: "com.apple.screencapture")? | |
47 | + .object(forKey: attr.rawValue) as? String | |
63 | 48 | } |
64 | 49 | |
65 | 50 | private func setScreencaptureAttribute(_ value: String, for attr: Attrubute) { |
66 | 51 | |
67 | - let process = Process() | |
68 | - process.launchPath = "/usr/bin/defaults" | |
69 | - process.arguments = ["write", "com.apple.screencapture", attr.rawValue, value] | |
70 | - process.launch() | |
71 | - process.waitUntilExit() | |
72 | - | |
73 | - guard process.terminationStatus == 0 else { | |
74 | - | |
75 | - print("Can not set location") | |
76 | - | |
77 | - return | |
78 | - } | |
52 | + UserDefaults(suiteName: "com.apple.screencapture")? | |
53 | + .set(value, forKey: attr.rawValue) | |
79 | 54 | } |
80 | 55 | } |