• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamephpguiwindowsc翻訳pythonomegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

macOSのスクリーンショットの保存場所を変更するメニュバーエクストラ


Commit MetaInfo

Revision7be03fdcd6b623db6b07aa993ea2b5370510976a (tree)
Time2018-07-01 13:46:30
Authormasakih <masakih@user...>
Commitermasakih

Log Message

Processを使わずUserDefaultsを使うようにした

Change Summary

Incremental Difference

--- a/GoInto/Screenshot.swift
+++ b/GoInto/Screenshot.swift
@@ -43,38 +43,13 @@ class Screenshot {
4343
4444 private func screencaptureAttribute(_ attr: Attrubute) -> String? {
4545
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
6348 }
6449
6550 private func setScreencaptureAttribute(_ value: String, for attr: Attrubute) {
6651
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)
7954 }
8055 }