diff --git a/DockPhobia.xcodeproj/project.pbxproj b/DockPhobia.xcodeproj/project.pbxproj index 2157965..b0bf234 100644 --- a/DockPhobia.xcodeproj/project.pbxproj +++ b/DockPhobia.xcodeproj/project.pbxproj @@ -6,23 +6,6 @@ objectVersion = 77; objects = { -/* Begin PBXContainerItemProxy section */ - A91E84AF2D82CF4300FC2E5F /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A91E84952D82CF4100FC2E5F /* Project object */; - proxyType = 1; - remoteGlobalIDString = A91E849C2D82CF4100FC2E5F; - remoteInfo = DockPhobia; - }; - A91E84B92D82CF4300FC2E5F /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A91E84952D82CF4100FC2E5F /* Project object */; - proxyType = 1; - remoteGlobalIDString = A91E849C2D82CF4100FC2E5F; - remoteInfo = DockPhobia; - }; -/* End PBXContainerItemProxy section */ - /* Begin PBXCopyFilesBuildPhase section */ A98E7EA02D836FBB0004DA00 /* Embed XPC Services */ = { isa = PBXCopyFilesBuildPhase; @@ -38,8 +21,6 @@ /* Begin PBXFileReference section */ A91E849D2D82CF4100FC2E5F /* DockPhobia.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DockPhobia.app; sourceTree = BUILT_PRODUCTS_DIR; }; - A91E84AE2D82CF4300FC2E5F /* DockPhobiaTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DockPhobiaTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - A91E84B82D82CF4300FC2E5F /* DockPhobiaUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DockPhobiaUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFileSystemSynchronizedRootGroup section */ @@ -68,20 +49,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - A91E84AB2D82CF4300FC2E5F /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - A91E84B52D82CF4300FC2E5F /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -99,8 +66,6 @@ isa = PBXGroup; children = ( A91E849D2D82CF4100FC2E5F /* DockPhobia.app */, - A91E84AE2D82CF4300FC2E5F /* DockPhobiaTests.xctest */, - A91E84B82D82CF4300FC2E5F /* DockPhobiaUITests.xctest */, ); name = Products; sourceTree = ""; @@ -131,52 +96,6 @@ productReference = A91E849D2D82CF4100FC2E5F /* DockPhobia.app */; productType = "com.apple.product-type.application"; }; - A91E84AD2D82CF4300FC2E5F /* DockPhobiaTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = A91E84C52D82CF4300FC2E5F /* Build configuration list for PBXNativeTarget "DockPhobiaTests" */; - buildPhases = ( - A91E84AA2D82CF4300FC2E5F /* Sources */, - A91E84AB2D82CF4300FC2E5F /* Frameworks */, - A91E84AC2D82CF4300FC2E5F /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - A91E84B02D82CF4300FC2E5F /* PBXTargetDependency */, - ); - fileSystemSynchronizedGroups = ( - A91E84B12D82CF4300FC2E5F /* DockPhobiaTests */, - ); - name = DockPhobiaTests; - packageProductDependencies = ( - ); - productName = DockPhobiaTests; - productReference = A91E84AE2D82CF4300FC2E5F /* DockPhobiaTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; - A91E84B72D82CF4300FC2E5F /* DockPhobiaUITests */ = { - isa = PBXNativeTarget; - buildConfigurationList = A91E84C82D82CF4300FC2E5F /* Build configuration list for PBXNativeTarget "DockPhobiaUITests" */; - buildPhases = ( - A91E84B42D82CF4300FC2E5F /* Sources */, - A91E84B52D82CF4300FC2E5F /* Frameworks */, - A91E84B62D82CF4300FC2E5F /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - A91E84BA2D82CF4300FC2E5F /* PBXTargetDependency */, - ); - fileSystemSynchronizedGroups = ( - A91E84BB2D82CF4300FC2E5F /* DockPhobiaUITests */, - ); - name = DockPhobiaUITests; - packageProductDependencies = ( - ); - productName = DockPhobiaUITests; - productReference = A91E84B82D82CF4300FC2E5F /* DockPhobiaUITests.xctest */; - productType = "com.apple.product-type.bundle.ui-testing"; - }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -190,14 +109,6 @@ A91E849C2D82CF4100FC2E5F = { CreatedOnToolsVersion = 16.2; }; - A91E84AD2D82CF4300FC2E5F = { - CreatedOnToolsVersion = 16.2; - TestTargetID = A91E849C2D82CF4100FC2E5F; - }; - A91E84B72D82CF4300FC2E5F = { - CreatedOnToolsVersion = 16.2; - TestTargetID = A91E849C2D82CF4100FC2E5F; - }; }; }; buildConfigurationList = A91E84982D82CF4100FC2E5F /* Build configuration list for PBXProject "DockPhobia" */; @@ -215,8 +126,6 @@ projectRoot = ""; targets = ( A91E849C2D82CF4100FC2E5F /* DockPhobia */, - A91E84AD2D82CF4300FC2E5F /* DockPhobiaTests */, - A91E84B72D82CF4300FC2E5F /* DockPhobiaUITests */, ); }; /* End PBXProject section */ @@ -229,20 +138,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - A91E84AC2D82CF4300FC2E5F /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - A91E84B62D82CF4300FC2E5F /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -253,35 +148,8 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - A91E84AA2D82CF4300FC2E5F /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - A91E84B42D82CF4300FC2E5F /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXSourcesBuildPhase section */ -/* Begin PBXTargetDependency section */ - A91E84B02D82CF4300FC2E5F /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = A91E849C2D82CF4100FC2E5F /* DockPhobia */; - targetProxy = A91E84AF2D82CF4300FC2E5F /* PBXContainerItemProxy */; - }; - A91E84BA2D82CF4300FC2E5F /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = A91E849C2D82CF4100FC2E5F /* DockPhobia */; - targetProxy = A91E84B92D82CF4300FC2E5F /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - /* Begin XCBuildConfiguration section */ A91E84C02D82CF4300FC2E5F /* Debug */ = { isa = XCBuildConfiguration; @@ -413,17 +281,21 @@ CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"DockPhobia/Preview Content\""; DEVELOPMENT_TEAM = P6PV2R9443; - ENABLE_HARDENED_RUNTIME = YES; + ENABLE_APP_SANDBOX = YES; + ENABLE_HARDENED_RUNTIME = NO; ENABLE_PREVIEWS = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = DockPhobia/Info.plist; INFOPLIST_KEY_LSUIElement = NO; + INFOPLIST_KEY_NSAppleEventsUsageDescription = "Needed to send AppleScript to move the Dock"; INFOPLIST_KEY_NSHumanReadableCopyright = ""; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/../Frameworks", ); MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.neon443.DockPhobia; + PRODUCT_BUNDLE_IDENTIFIER = dev.neon443.DockPhobia; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; @@ -442,91 +314,27 @@ CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"DockPhobia/Preview Content\""; DEVELOPMENT_TEAM = P6PV2R9443; - ENABLE_HARDENED_RUNTIME = YES; + ENABLE_APP_SANDBOX = YES; + ENABLE_HARDENED_RUNTIME = NO; ENABLE_PREVIEWS = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = DockPhobia/Info.plist; INFOPLIST_KEY_LSUIElement = NO; + INFOPLIST_KEY_NSAppleEventsUsageDescription = "Needed to send AppleScript to move the Dock"; INFOPLIST_KEY_NSHumanReadableCopyright = ""; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/../Frameworks", ); MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.neon443.DockPhobia; + PRODUCT_BUNDLE_IDENTIFIER = dev.neon443.DockPhobia; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; }; name = Release; }; - A91E84C62D82CF4300FC2E5F /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - BUNDLE_LOADER = "$(TEST_HOST)"; - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = P6PV2R9443; - GENERATE_INFOPLIST_FILE = YES; - MACOSX_DEPLOYMENT_TARGET = 15.2; - MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.neon443.DockPhobiaTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_EMIT_LOC_STRINGS = NO; - SWIFT_VERSION = 5.0; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/DockPhobia.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/DockPhobia"; - }; - name = Debug; - }; - A91E84C72D82CF4300FC2E5F /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - BUNDLE_LOADER = "$(TEST_HOST)"; - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = P6PV2R9443; - GENERATE_INFOPLIST_FILE = YES; - MACOSX_DEPLOYMENT_TARGET = 15.2; - MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.neon443.DockPhobiaTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_EMIT_LOC_STRINGS = NO; - SWIFT_VERSION = 5.0; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/DockPhobia.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/DockPhobia"; - }; - name = Release; - }; - A91E84C92D82CF4300FC2E5F /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = P6PV2R9443; - GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.neon443.DockPhobiaUITests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_EMIT_LOC_STRINGS = NO; - SWIFT_VERSION = 5.0; - TEST_TARGET_NAME = DockPhobia; - }; - name = Debug; - }; - A91E84CA2D82CF4300FC2E5F /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = P6PV2R9443; - GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.neon443.DockPhobiaUITests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_EMIT_LOC_STRINGS = NO; - SWIFT_VERSION = 5.0; - TEST_TARGET_NAME = DockPhobia; - }; - name = Release; - }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -548,24 +356,6 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - A91E84C52D82CF4300FC2E5F /* Build configuration list for PBXNativeTarget "DockPhobiaTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - A91E84C62D82CF4300FC2E5F /* Debug */, - A91E84C72D82CF4300FC2E5F /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - A91E84C82D82CF4300FC2E5F /* Build configuration list for PBXNativeTarget "DockPhobiaUITests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - A91E84C92D82CF4300FC2E5F /* Debug */, - A91E84CA2D82CF4300FC2E5F /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; /* End XCConfigurationList section */ }; rootObject = A91E84952D82CF4100FC2E5F /* Project object */; diff --git a/DockPhobia.xcodeproj/xcshareddata/xcschemes/DockPhobia.xcscheme b/DockPhobia.xcodeproj/xcshareddata/xcschemes/DockPhobia.xcscheme new file mode 100644 index 0000000..4705372 --- /dev/null +++ b/DockPhobia.xcodeproj/xcshareddata/xcschemes/DockPhobia.xcscheme @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DockPhobia.xcodeproj/xcuserdata/neon443.xcuserdatad/xcschemes/xcschememanagement.plist b/DockPhobia.xcodeproj/xcuserdata/neon443.xcuserdatad/xcschemes/xcschememanagement.plist index c886bc1..0df0b42 100644 --- a/DockPhobia.xcodeproj/xcuserdata/neon443.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/DockPhobia.xcodeproj/xcuserdata/neon443.xcuserdatad/xcschemes/xcschememanagement.plist @@ -9,10 +9,23 @@ orderHint 0 - DockPhobiaHelper.xcscheme_^#shared#^_ + + SuppressBuildableAutocreation + + A91E849C2D82CF4100FC2E5F - orderHint - 1 + primary + + + A91E84AD2D82CF4300FC2E5F + + primary + + + A91E84B72D82CF4300FC2E5F + + primary + diff --git a/DockPhobia.xcworkspace/contents.xcworkspacedata b/DockPhobia.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..4e7ae3c --- /dev/null +++ b/DockPhobia.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/DockPhobia.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/DockPhobia.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..0c67376 --- /dev/null +++ b/DockPhobia.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,5 @@ + + + + + diff --git a/DockPhobia.xcworkspace/xcuserdata/neon443.xcuserdatad/WorkspaceSettings.xcsettings b/DockPhobia.xcworkspace/xcuserdata/neon443.xcuserdatad/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..f1ebe29 --- /dev/null +++ b/DockPhobia.xcworkspace/xcuserdata/neon443.xcuserdatad/WorkspaceSettings.xcsettings @@ -0,0 +1,18 @@ + + + + + BuildLocationStyle + UseAppPreferences + CustomBuildIntermediatesPath + Build/Intermediates.noindex + CustomBuildLocationType + RelativeToDerivedData + CustomBuildProductsPath + Build/Products + DerivedDataLocationStyle + Default + ShowSharedSchemesAutomaticallyEnabled + + + diff --git a/DockPhobia/ContentView.swift b/DockPhobia/ContentView.swift index 2cefcc1..e935565 100644 --- a/DockPhobia/ContentView.swift +++ b/DockPhobia/ContentView.swift @@ -8,22 +8,21 @@ import SwiftUI struct ContentView: View { - @Binding var enabled: Bool + @Binding var isTracking: Bool @State var mouseloc = NSEvent.mouseLocation + var body: some View { VStack { - Text("\(NSEvent.mouseLocation)") - Toggle("on", isOn: $enabled) - .toggleStyle(SwitchToggleStyle()) + Text("Screen size: \(getScreenSize())") Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") Spacer() - Button("df") { + Button("Start") { startTrackingMouse() } - Button("undf") { + Button("Stop") { stopTrackingMouse() } Button() { @@ -37,5 +36,5 @@ struct ContentView: View { } #Preview { - ContentView(enabled: .constant(true)) + ContentView(isTracking: .constant(true)) } diff --git a/DockPhobia/DockPhobia.entitlements b/DockPhobia/DockPhobia.entitlements index 18aff0c..2527cd0 100644 --- a/DockPhobia/DockPhobia.entitlements +++ b/DockPhobia/DockPhobia.entitlements @@ -2,9 +2,13 @@ - com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - + com.apple.security.temporary-exception.apple-events + + System Events + + com.apple.security.temporary-exception.mach-lookup.global-name + + com.apple.tsm.portname + diff --git a/DockPhobia/DockPhobiaApp.swift b/DockPhobia/DockPhobiaApp.swift index ca5bf29..2eb4593 100644 --- a/DockPhobia/DockPhobiaApp.swift +++ b/DockPhobia/DockPhobiaApp.swift @@ -45,24 +45,6 @@ import CoreGraphics ////} import Foundation -func moveDock() { - let process = Process() - process.executableURL = URL(fileURLWithPath: "/usr/bin/osascript") - - if let scriptPath = Bundle.main.path(forResource: "/Users/neon443/Documents/Xcode/DockPhobia/DockPhobia/script.scpt", ofType: "scpt") { - process.arguments = [scriptPath] - - do { - try process.run() - process.waitUntilExit() - } catch { - print("error") - } - } else { - print("error script not found") - } -} - @main struct DockPhobiaApp: App { enum DockPosition: String { @@ -71,18 +53,56 @@ struct DockPhobiaApp: App { case bottom } - @State var enabled: Bool = true - - var body: some Scene { - WindowGroup { - ContentView(enabled: $enabled) + @State var preferencesOpen: Bool = false + @State var isTracking: Bool = false + func toggleTracking() { + if isTracking { + stopTrackingMouse() + } else { + startTrackingMouse() } - MenuBarExtra("Dock Phobia", systemImage: "cursorarrow\(enabled ? "" : ".slash")") { - Toggle(enabled ? "Enabled" : "Disabled", isOn: $enabled) + isTracking.toggle() + } + var body: some Scene { + // WindowGroup { + // ContentView(isTracking: $isTracking) + // } + MenuBarExtra("Dock Phobia", systemImage: "cursorarrow\(isTracking ? "" : ".slash")") { + Text(isTracking ? "Enabled" : "Disabled") + Text("\(getScreenSize())") + Button("Toggle tracking") { + toggleTracking() + } + .keyboardShortcut(" ", modifiers: []) Divider() - Button("Right") { - moveDock() + Button("Settings") { + preferencesOpen.toggle() + } + .keyboardShortcut(",") + Divider() + Button("try shell") { + print(shell("echo hello") ?? "fuck me") + } + Divider() + Button("Move Dock to Right") { + moveDock("right") + } + Divider() + Button("Move Dock to Right2") { + moveDockWithDefaults("right") + } + Button("Move Dock to Left") { + moveDock("left") + } + Button("Move Dock to Bottom") { + moveDock("bottom") + } + Button("Get Dock orientation") { + print(getDockSide()) + } + Button("Get Dock Height Percentage") { + print(getDockHeightPercentage()) } Button("Quit") { NSApplication.shared.terminate(nil) @@ -92,11 +112,65 @@ struct DockPhobiaApp: App { } } +func shell(_ command: String) -> (output: String?, error: String?) { + let process = Process() + let pipe = Pipe() + let pipeError = Pipe() + + process.executableURL = URL(fileURLWithPath: "/bin/bash") + process.arguments = ["-c", command] + process.standardOutput = pipe + process.standardError = pipeError + + let outputHandle = pipe.fileHandleForReading + let errorHandle = pipeError.fileHandleForReading + + process.launch() + process.waitUntilExit() + + let data = outputHandle.readDataToEndOfFile() + let dataError = errorHandle.readDataToEndOfFile() + + let output = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) + let outputError = String(data: dataError, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) + + return (output, outputError) +} + +func getDockSide() -> String { + let result = shell("defaults read com.apple.Dock orientation") + + if let error = result.error { + print("Error: \(error)") + return "unknown" + } + + if let output = result.output, !output.isEmpty { + print("Dock is on the \(output)") + return output + } + + return "unknown" +} + // global event tap var eventTap: CFMachPort? +func getDockHeightPercentage() -> Double { + guard let screen = NSScreen.main else { return 0 } + + let fullHeight = screen.frame.height + let visibleHeight = screen.visibleFrame.height + + let dockHeight = fullHeight - visibleHeight + let percentage = (dockHeight / fullHeight) * 100 + + return percentage +} + func startTrackingMouse() { let mask = CGEventMask(1 << CGEventType.mouseMoved.rawValue) + let screenDimensions = getScreenSize() //try creating event tap eventTap = CGEvent.tapCreate( @@ -124,3 +198,86 @@ func startTrackingMouse() { print(" failed to create event tap.") } } + + +func stopTrackingMouse() { + if let eventTap = eventTap { + // disable event tap + CGEvent.tapEnable(tap: eventTap, enable: false) + + // stops run loop + CFRunLoopPerformBlock(CFRunLoopGetMain(), CFRunLoopMode.defaultMode.rawValue) { + CFRunLoopStop(CFRunLoopGetMain()) + } + + print(" mouse tracking has stopped") + } else { + print(" no active event tap to stop") + } +} + +func getScreenSize() -> (x: CGFloat, y: CGFloat) { + if let screen = NSScreen.main { + let screenFrame = screen.frame + let maxWidth = screenFrame.width + let maxHeight = screenFrame.height +// print("screen res: \(maxWidth)x\(maxHeight)") + return (maxWidth, maxHeight) + } else { + print("you have no screen") + print("what the fuck") + return (-1.0, -1.0) //help me... i am not accounting for edge cases like this shit + } +} + +func moveDock(_ to: String) { + print(NSApplication.shared.isAccessibilityEnabled()) + let validPositions = ["left", "right", "bottom"] + guard validPositions.contains(to) else { + print("Invalid Dock position: \(to)") + return + } + + let script = """ + tell application "System Events" + tell dock preferences + set screen edge to \(to) + 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)") + } +} + +func moveDockWithDefaults(_ to: String) { + let validPositions = ["left", "right", "bottom"] + guard validPositions.contains(to) else { + print("Invalid Dock position: \(to)") + return + } + + let command = "defaults write com.apple.Dock orientation -string \(to);launchctl kickstart -k gui/$(id -u)/com.apple.Dock" + let result = shell(command) + + if let error = result.error { + print("Error moving Dock: \(error)") + } else { + print("Dock moved to \(to)") + } +} diff --git a/DockPhobia/Info.plist b/DockPhobia/Info.plist new file mode 100644 index 0000000..d1a5b03 --- /dev/null +++ b/DockPhobia/Info.plist @@ -0,0 +1,18 @@ + + + + + NSAppleEventsUsageDescription + allow it + NSAccessibilitysUsageDescription + allow it + + com.apple.security.scripting-targets + + com.apple.mail + + com.apple.mail.compose + + + + diff --git a/Info.plist b/Info.plist new file mode 100644 index 0000000..fb8d067 --- /dev/null +++ b/Info.plist @@ -0,0 +1,12 @@ + + + + + +