rewrote basic fucntionality in python, this had better work

This commit is contained in:
neon443
2025-03-15 12:51:36 +00:00
parent 9f60a4e124
commit 0f1b0b49c7
11 changed files with 388 additions and 263 deletions

View File

@@ -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 = "<group>";
@@ -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 */;

View File

@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1620"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A91E849C2D82CF4100FC2E5F"
BuildableName = "DockPhobia.app"
BlueprintName = "DockPhobia"
ReferencedContainer = "container:DockPhobia.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A91E84AD2D82CF4300FC2E5F"
BuildableName = "DockPhobiaTests.xctest"
BlueprintName = "DockPhobiaTests"
ReferencedContainer = "container:DockPhobia.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A91E84B72D82CF4300FC2E5F"
BuildableName = "DockPhobiaUITests.xctest"
BlueprintName = "DockPhobiaUITests"
ReferencedContainer = "container:DockPhobia.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A91E849C2D82CF4100FC2E5F"
BuildableName = "DockPhobia.app"
BlueprintName = "DockPhobia"
ReferencedContainer = "container:DockPhobia.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A91E849C2D82CF4100FC2E5F"
BuildableName = "DockPhobia.app"
BlueprintName = "DockPhobia"
ReferencedContainer = "container:DockPhobia.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -9,10 +9,23 @@
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>DockPhobiaHelper.xcscheme_^#shared#^_</key>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>A91E849C2D82CF4100FC2E5F</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<key>primary</key>
<true/>
</dict>
<key>A91E84AD2D82CF4300FC2E5F</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>A91E84B72D82CF4300FC2E5F</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "container:DockPhobia.xcodeproj">
</FileRef>
</Workspace>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildLocationStyle</key>
<string>UseAppPreferences</string>
<key>CustomBuildIntermediatesPath</key>
<string>Build/Intermediates.noindex</string>
<key>CustomBuildLocationType</key>
<string>RelativeToDerivedData</string>
<key>CustomBuildProductsPath</key>
<string>Build/Products</string>
<key>DerivedDataLocationStyle</key>
<string>Default</string>
<key>ShowSharedSchemesAutomaticallyEnabled</key>
<true/>
</dict>
</plist>

View File

@@ -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))
}

View File

@@ -2,9 +2,13 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.temporary-exception.apple-events</key>
<array>
<string>System Events</string>
</array>
<key>com.apple.security.temporary-exception.mach-lookup.global-name</key>
<array>
<string>com.apple.tsm.portname</string>
</array>
</dict>
</plist>

View File

@@ -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)")
}
}

18
DockPhobia/Info.plist Normal file
View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppleEventsUsageDescription</key>
<string>allow it</string>
<key>NSAccessibilitysUsageDescription</key>
<string>allow it</string>
<com.apple.security.automation.apple-events>
<key>com.apple.security.scripting-targets</key>
<dict>
<key>com.apple.mail</key>
<array>
<string>com.apple.mail.compose</string>
</array>
</dict>
</dict>
</plist>

12
Info.plist Normal file
View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
Info.plist
DockPhobia
Created by neon443 on 14/03/2025.
Copyright (c) 2025 ___ORGANIZATIONNAME___. All rights reserved.
-->
<plist version="1.0">
<dict/>
</plist>