mirror of
https://github.com/neon443/DockPhobia.git
synced 2026-03-11 06:49:12 +00:00
rewrote moveDock(_ to: String)
This commit is contained in:
@@ -14,40 +14,26 @@
|
||||
filePath = "DockPhobia/DockPhobiaApp.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "145"
|
||||
endingLineNumber = "145"
|
||||
startingLineNumber = "178"
|
||||
endingLineNumber = "178"
|
||||
landmarkName = "getDockSide()"
|
||||
landmarkType = "9">
|
||||
<Locations>
|
||||
<Location
|
||||
uuid = "6F6CFA28-932B-49B9-8838-CF4194EDBCCF - 71947627bacaba5"
|
||||
shouldBeEnabled = "Yes"
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "C0D2802D-073C-4D69-9782-96DD9EC538DF"
|
||||
shouldBeEnabled = "No"
|
||||
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"
|
||||
filePath = "DockPhobia/DockPhobiaApp.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "144"
|
||||
endingLineNumber = "144">
|
||||
</Location>
|
||||
<Location
|
||||
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>
|
||||
startingLineNumber = "258"
|
||||
endingLineNumber = "258"
|
||||
landmarkName = "moveDock(_:)"
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
BIN
DockPhobiaPy/.DS_Store
vendored
BIN
DockPhobiaPy/.DS_Store
vendored
Binary file not shown.
Reference in New Issue
Block a user