Skip to content

Instantly share code, notes, and snippets.

@unixzii
Last active November 4, 2022 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unixzii/7091dda6aea958c6da669e436365df65 to your computer and use it in GitHub Desktop.
Save unixzii/7091dda6aea958c6da669e436365df65 to your computer and use it in GitHub Desktop.
Perform some of Dock actions programmatically.
#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