mirror of
https://github.com/neon443/DockPhobia.git
synced 2026-03-11 23:06:17 +00:00
rewrote moveDock(_ to: String)
This commit is contained in:
@@ -14,40 +14,26 @@
|
|||||||
filePath = "DockPhobia/DockPhobiaApp.swift"
|
filePath = "DockPhobia/DockPhobiaApp.swift"
|
||||||
startingColumnNumber = "9223372036854775807"
|
startingColumnNumber = "9223372036854775807"
|
||||||
endingColumnNumber = "9223372036854775807"
|
endingColumnNumber = "9223372036854775807"
|
||||||
startingLineNumber = "145"
|
startingLineNumber = "178"
|
||||||
endingLineNumber = "145"
|
endingLineNumber = "178"
|
||||||
landmarkName = "getDockSide()"
|
landmarkName = "getDockSide()"
|
||||||
landmarkType = "9">
|
landmarkType = "9">
|
||||||
<Locations>
|
</BreakpointContent>
|
||||||
<Location
|
</BreakpointProxy>
|
||||||
uuid = "6F6CFA28-932B-49B9-8838-CF4194EDBCCF - 71947627bacaba5"
|
<BreakpointProxy
|
||||||
shouldBeEnabled = "Yes"
|
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||||
ignoreCount = "0"
|
<BreakpointContent
|
||||||
continueAfterRunningActions = "No"
|
uuid = "C0D2802D-073C-4D69-9782-96DD9EC538DF"
|
||||||
symbolName = "DockPhobia.getDockSide() -> Swift.String"
|
shouldBeEnabled = "No"
|
||||||
moduleName = "DockPhobia.debug.dylib"
|
ignoreCount = "0"
|
||||||
usesParentBreakpointCondition = "Yes"
|
continueAfterRunningActions = "No"
|
||||||
urlString = "file:///Users/neon443/Documents/Xcode/DockPhobia/DockPhobia/DockPhobiaApp.swift"
|
filePath = "DockPhobia/DockPhobiaApp.swift"
|
||||||
startingColumnNumber = "9223372036854775807"
|
startingColumnNumber = "9223372036854775807"
|
||||||
endingColumnNumber = "9223372036854775807"
|
endingColumnNumber = "9223372036854775807"
|
||||||
startingLineNumber = "144"
|
startingLineNumber = "258"
|
||||||
endingLineNumber = "144">
|
endingLineNumber = "258"
|
||||||
</Location>
|
landmarkName = "moveDock(_:)"
|
||||||
<Location
|
landmarkType = "9">
|
||||||
uuid = "6F6CFA28-932B-49B9-8838-CF4194EDBCCF - 71947627bacab84"
|
|
||||||
shouldBeEnabled = "Yes"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
symbolName = "DockPhobia.getDockSide() -> Swift.String"
|
|
||||||
moduleName = "DockPhobia.debug.dylib"
|
|
||||||
usesParentBreakpointCondition = "Yes"
|
|
||||||
urlString = "file:///Users/neon443/Documents/Xcode/DockPhobia/DockPhobia/DockPhobiaApp.swift"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "145"
|
|
||||||
endingLineNumber = "145">
|
|
||||||
</Location>
|
|
||||||
</Locations>
|
|
||||||
</BreakpointContent>
|
</BreakpointContent>
|
||||||
</BreakpointProxy>
|
</BreakpointProxy>
|
||||||
</Breakpoints>
|
</Breakpoints>
|
||||||
|
|||||||
@@ -139,6 +139,39 @@ func shell(_ command: String) -> (output: String?, error: String?) {
|
|||||||
return (output: output, error: outputError)
|
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 {
|
func getDockSide() -> String {
|
||||||
let result = shell("defaults read com.apple.Dock orientation")
|
let result = shell("defaults read com.apple.Dock orientation")
|
||||||
print("dock is on the \(result.output ?? "idk")")
|
print("dock is on the \(result.output ?? "idk")")
|
||||||
@@ -162,7 +195,6 @@ func getDockHeightPercentage() -> Double {
|
|||||||
|
|
||||||
func startTrackingMouse() {
|
func startTrackingMouse() {
|
||||||
let mask = CGEventMask(1 << CGEventType.mouseMoved.rawValue)
|
let mask = CGEventMask(1 << CGEventType.mouseMoved.rawValue)
|
||||||
let screenDimensions = getScreenSize()
|
|
||||||
|
|
||||||
//try creating event tap
|
//try creating event tap
|
||||||
eventTap = CGEvent.tapCreate(
|
eventTap = CGEvent.tapCreate(
|
||||||
@@ -223,13 +255,11 @@ func getScreenSize() -> (x: CGFloat, y: CGFloat) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func moveDock(_ to: String) {
|
func moveDock(_ to: String) {
|
||||||
print(NSApplication.shared.isAccessibilityEnabled())
|
let validPos = ["left", "bottom", "right"]
|
||||||
let validPositions = ["left", "right", "bottom"]
|
guard validPos.contains(to) else {
|
||||||
guard validPositions.contains(to) else {
|
print("invalid dock position")
|
||||||
print("Invalid Dock position: \(to)")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let script = """
|
let script = """
|
||||||
tell application "System Events"
|
tell application "System Events"
|
||||||
tell dock preferences
|
tell dock preferences
|
||||||
@@ -237,22 +267,6 @@ func moveDock(_ to: String) {
|
|||||||
end tell
|
end tell
|
||||||
end tell
|
end tell
|
||||||
"""
|
"""
|
||||||
|
let result = osascript(script)
|
||||||
let process = Process()
|
return
|
||||||
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)")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
DockPhobiaPy/.DS_Store
vendored
BIN
DockPhobiaPy/.DS_Store
vendored
Binary file not shown.
Reference in New Issue
Block a user