Last active
November 4, 2022 04:45
-
-
Save unixzii/7091dda6aea958c6da669e436365df65 to your computer and use it in GitHub Desktop.
Perform some of Dock actions programmatically.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <dlfcn.h> | |
void sendMessageToDock(NSString *message) { | |
static dispatch_once_t onceToken; | |
static void (*ptrCoreDockSendNotification)(CFStringRef, int) = NULL; | |
dispatch_once(&onceToken, ^{ | |
void *handle = dlopen("/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/HIServices", RTLD_LAZY); | |
if (!handle) { | |
return; | |
} | |
ptrCoreDockSendNotification = dlsym(handle, "CoreDockSendNotification"); | |
}); | |
if (ptrCoreDockSendNotification) { | |
ptrCoreDockSendNotification((CFStringRef) message, 0); | |
} | |
} | |
int main(int argc, const char * argv[]) { | |
/* | |
Possible messages: | |
- "com.apple.launchpad.toggle": Toggle Launchpad | |
- "com.apple.expose.awake": Toggle Mission Control | |
- "com.apple.expose.front.awake": Toggle App Exposé | |
- "com.apple.showdesktop.awake": Toggle desktop | |
*/ | |
sendMessageToDock(@"com.apple.launchpad.toggle"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment