From a134920ddad52a183bc7b46836e41cc813ca0600 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Tue, 18 Mar 2025 17:41:12 +0000 Subject: [PATCH] rewrote moveDock(_ to: String) --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 50 +++++--------- DockPhobia/DockPhobiaApp.swift | 62 +++++++++++------- DockPhobiaPy/.DS_Store | Bin 6148 -> 6148 bytes 3 files changed, 56 insertions(+), 56 deletions(-) diff --git a/DockPhobia.xcworkspace/xcuserdata/neon443.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/DockPhobia.xcworkspace/xcuserdata/neon443.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index a5a8a28..8b5c80f 100644 --- a/DockPhobia.xcworkspace/xcuserdata/neon443.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/DockPhobia.xcworkspace/xcuserdata/neon443.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -14,40 +14,26 @@ filePath = "DockPhobia/DockPhobiaApp.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "145" - endingLineNumber = "145" + startingLineNumber = "178" + endingLineNumber = "178" landmarkName = "getDockSide()" landmarkType = "9"> - - - - - - + + + + diff --git a/DockPhobia/DockPhobiaApp.swift b/DockPhobia/DockPhobiaApp.swift index 13c5fe4..6d5f010 100644 --- a/DockPhobia/DockPhobiaApp.swift +++ b/DockPhobia/DockPhobiaApp.swift @@ -139,6 +139,39 @@ func shell(_ command: String) -> (output: String?, error: String?) { return (output: output, error: outputError) } +func osascript(_ script: String) -> (output: String?, error: String?) { + let process = Process() + let outputPipe = Pipe() + let outputErrorPipe = Pipe() + + process.executableURL = URL(fileURLWithPath: "/usr/bin/osascript") + process.arguments = ["-e", script] + process.standardOutput = outputPipe + process.standardError = outputErrorPipe + + process.launch() + process.waitUntilExit() + + let outputHandle = outputPipe.fileHandleForReading.readDataToEndOfFile() + let outputErrorHandle = outputErrorPipe.fileHandleForReading.readDataToEndOfFile() + + let outputData = String( + data: outputHandle, + encoding: .utf8 + )? + .trimmingCharacters( + in: .whitespacesAndNewlines + ) + let outputErrorData = String( + data: outputErrorHandle, + encoding: .utf8 + )? + .trimmingCharacters( + in: .whitespacesAndNewlines + ) + return (outputData, outputErrorData) +} + func getDockSide() -> String { let result = shell("defaults read com.apple.Dock orientation") print("dock is on the \(result.output ?? "idk")") @@ -162,7 +195,6 @@ func getDockHeightPercentage() -> Double { func startTrackingMouse() { let mask = CGEventMask(1 << CGEventType.mouseMoved.rawValue) - let screenDimensions = getScreenSize() //try creating event tap eventTap = CGEvent.tapCreate( @@ -223,13 +255,11 @@ func getScreenSize() -> (x: CGFloat, y: CGFloat) { } func moveDock(_ to: String) { - print(NSApplication.shared.isAccessibilityEnabled()) - let validPositions = ["left", "right", "bottom"] - guard validPositions.contains(to) else { - print("Invalid Dock position: \(to)") + let validPos = ["left", "bottom", "right"] + guard validPos.contains(to) else { + print("invalid dock position") return } - let script = """ tell application "System Events" tell dock preferences @@ -237,22 +267,6 @@ func moveDock(_ to: String) { end tell end tell """ - - let process = Process() - process.executableURL = URL(fileURLWithPath: "/usr/bin/osascript") - process.arguments = ["-e", script] - - do { - try process.run() - process.waitUntilExit() - - let status = process.terminationStatus - if status == 0 { - print("Dock moved to \(to)") - } else { - print("Failed to move dock, status: \(status)") - } - } catch { - print("Error running AppleScript: \(error)") - } + let result = osascript(script) + return } diff --git a/DockPhobiaPy/.DS_Store b/DockPhobiaPy/.DS_Store index f66cd179579bc968aa900beec930999b0185ce7f..cd9c10d8ff02d0155a914717ca5eddb9bbcbd716 100644 GIT binary patch delta 113 zcmZoMXfc?uEH=oJfq{XAp^PDwA&;RfH{Zo2DJMS(D8@0Dxj@+b$T3G$`4qhJ1sR6H c$@#ejKs^jhCkr+UGJa#5SirZLo#QV*0E;gkGynhq delta 113 zcmZoMXfc?uEOwSF0|NsKLm5LVLmop}ZoZ34QcivnP>iGV8`A~uBgY(3>Pjj0Wkg`>;M1&