You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ive been loving so far sketchybar, however im trying to toggle the original macos wifi popup, ive read the docs and created this helper (a modified version of the one used in this dotfiles
#include<Carbon/Carbon.h>#include<stdio.h>#include<string.h>voidax_init() {
constvoid*keys[] = { kAXTrustedCheckOptionPrompt };
constvoid*values[] = { kCFBooleanTrue };
CFDictionaryRefoptions=CFDictionaryCreate(
kCFAllocatorDefault,
keys,
values,
sizeof(keys) / sizeof(*keys),
&kCFCopyStringDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks
);
booltrusted=AXIsProcessTrustedWithOptions(options);
CFRelease(options);
if (!trusted) {
printf("Error: Application is not trusted. Please grant accessibility permissions.\n");
exit(1);
}
}
voidax_perform_click(AXUIElementRefelement) {
if (!element) return;
AXUIElementPerformAction(element, kAXCancelAction);
usleep(150000);
AXUIElementPerformAction(element, kAXPressAction);
}
CFStringRefax_get_title(AXUIElementRefelement) {
CFTypeReftitle=NULL;
AXErrorerror=AXUIElementCopyAttributeValue(element, kAXTitleAttribute, &title);
if (error!=kAXErrorSuccess) returnNULL;
returntitle;
}
voidax_select_menu_option(AXUIElementRefapp, intid) {
AXUIElementRefmenubars_ref=NULL;
CFArrayRefchildren_ref=NULL;
AXErrorerror=AXUIElementCopyAttributeValue(app, kAXMenuBarAttribute, (CFTypeRef*)&menubars_ref);
if (error==kAXErrorSuccess) {
error=AXUIElementCopyAttributeValue(menubars_ref, kAXVisibleChildrenAttribute, (CFTypeRef*)&children_ref);
if (error==kAXErrorSuccess) {
uint32_tcount=CFArrayGetCount(children_ref);
if (id<count) {
AXUIElementRefitem=CFArrayGetValueAtIndex(children_ref, id);
ax_perform_click(item);
}
if (children_ref) CFRelease(children_ref);
}
if (menubars_ref) CFRelease(menubars_ref);
}
}
voidax_print_menu_options(AXUIElementRefapp) {
AXUIElementRefmenubars_ref=NULL;
CFArrayRefchildren_ref=NULL;
AXErrorerror=AXUIElementCopyAttributeValue(app, kAXMenuBarAttribute, (CFTypeRef*)&menubars_ref);
if (error==kAXErrorSuccess) {
error=AXUIElementCopyAttributeValue(menubars_ref, kAXVisibleChildrenAttribute, (CFTypeRef*)&children_ref);
if (error==kAXErrorSuccess) {
uint32_tcount=CFArrayGetCount(children_ref);
for (inti=0; i<count; i++) {
AXUIElementRefitem=CFArrayGetValueAtIndex(children_ref, i);
CFTypeReftitle=ax_get_title(item);
if (title) {
uint32_tbuffer_len=2*CFStringGetLength(title);
charbuffer[buffer_len];
CFStringGetCString(title, buffer, buffer_len, kCFStringEncodingUTF8);
printf("%d: %s\n", i, buffer);
CFRelease(title);
}
}
}
if (menubars_ref) CFRelease(menubars_ref);
if (children_ref) CFRelease(children_ref);
}
}
AXUIElementRefax_get_extra_menu_item(char*alias) {
pid_tpid=0;
CGRectbounds=CGRectNull;
CFArrayRefwindow_list=CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID);
charowner_buffer[256];
charname_buffer[256];
charbuffer[512];
intwindow_count=CFArrayGetCount(window_list);
char*alias_owner=strtok(alias, ",");
char*alias_name=strtok(NULL, ",");
printf("Debug: Searching for alias - Owner: %s, Name: %s\n", alias_owner, alias_name);
for (inti=0; i<window_count; ++i) {
CFDictionaryRefdictionary=CFArrayGetValueAtIndex(window_list, i);
if (!dictionary) continue;
CFStringRefowner_ref=CFDictionaryGetValue(dictionary, kCGWindowOwnerName);
CFNumberRefowner_pid_ref=CFDictionaryGetValue(dictionary, kCGWindowOwnerPID);
CFStringRefname_ref=CFDictionaryGetValue(dictionary, kCGWindowName);
CFNumberReflayer_ref=CFDictionaryGetValue(dictionary, kCGWindowLayer);
CFDictionaryRefbounds_ref=CFDictionaryGetValue(dictionary, kCGWindowBounds);
if (!owner_ref|| !owner_pid_ref|| !layer_ref|| !bounds_ref) continue;
long long intlayer=0;
CFNumberGetValue(layer_ref, CFNumberGetType(layer_ref), &layer);
uint64_towner_pid=0;
CFNumberGetValue(owner_pid_ref, CFNumberGetType(owner_pid_ref), &owner_pid);
if (layer!=0x19) {
printf("Debug: Skipping window due to layer != 0x19\n");
continue;
}
bounds=CGRectNull;
if (!CGRectMakeWithDictionaryRepresentation(bounds_ref, &bounds)) continue;
CFStringGetCString(owner_ref, owner_buffer, sizeof(owner_buffer), kCFStringEncodingUTF8);
if (name_ref) {
CFStringGetCString(name_ref, name_buffer, sizeof(name_buffer), kCFStringEncodingUTF8);
snprintf(buffer, sizeof(buffer), "%s (%s)", name_buffer, owner_buffer);
} else {
strncpy(buffer, owner_buffer, sizeof(buffer));
}
printf("Debug: Checking window - %s\n", buffer);
if (strstr(buffer, alias_owner) !=NULL&& (alias_name==NULL||strstr(buffer, alias_name) !=NULL)) {
pid=owner_pid;
printf("Debug: Match found - %s\n", buffer);
break;
}
}
CFRelease(window_list);
if (!pid) {
printf("Debug: No matching window found\n");
returnNULL;
}
AXUIElementRefapp=AXUIElementCreateApplication(pid);
if (!app) {
printf("Debug: Failed to create AXUIElement for pid %d\n", pid);
returnNULL;
}
AXUIElementRefresult=NULL;
CFTypeRefextras=NULL;
CFArrayRefchildren_ref=NULL;
AXErrorerror=AXUIElementCopyAttributeValue(app, kAXExtrasMenuBarAttribute, &extras);
if (error==kAXErrorSuccess) {
error=AXUIElementCopyAttributeValue(extras, kAXVisibleChildrenAttribute, (CFTypeRef*)&children_ref);
if (error==kAXErrorSuccess) {
uint32_tcount=CFArrayGetCount(children_ref);
printf("Debug: Found %d extras menu items\n", count);
for (uint32_ti=0; i<count; i++) {
AXUIElementRefitem=CFArrayGetValueAtIndex(children_ref, i);
CFTypeRefposition_ref=NULL;
CFTypeRefsize_ref=NULL;
CFTypeReftitle_ref=NULL;
AXUIElementCopyAttributeValue(item, kAXPositionAttribute, &position_ref);
AXUIElementCopyAttributeValue(item, kAXSizeAttribute, &size_ref);
AXUIElementCopyAttributeValue(item, kAXTitleAttribute, &title_ref);
if (!position_ref|| !size_ref) continue;
CGPointposition=CGPointZero;
AXValueGetValue(position_ref, kAXValueCGPointType, &position);
CGSizesize=CGSizeZero;
AXValueGetValue(size_ref, kAXValueCGSizeType, &size);
chartitle_buffer[256] = {0};
if (title_ref) {
CFStringGetCString(title_ref, title_buffer, sizeof(title_buffer), kCFStringEncodingUTF8);
CFRelease(title_ref);
}
printf("Debug: Extras item %d - Title: %s, Position: (%.2f, %.2f)\n", i, title_buffer, position.x, position.y);
if (fabs(position.x-bounds.origin.x) <= 10|| (alias_name!=NULL&&strstr(title_buffer, alias_name) !=NULL)) {
result=item;
printf("Debug: Selected extras item %d\n", i);
break;
}
CFRelease(position_ref);
CFRelease(size_ref);
}
} else {
printf("Debug: Failed to get visible children of extras menu\n");
}
if (children_ref) CFRelease(children_ref);
} else {
printf("Debug: Failed to get extras menu bar attribute\n");
}
CFRelease(app);
returnresult;
}
externintSLSMainConnectionID();
externvoidSLSSetMenuBarVisibilityOverrideOnDisplay(intcid, intdid, boolenabled);
externvoidSLSSetMenuBarInsetAndAlpha(intcid, doubleu1, doubleu2, floatalpha);
voidax_select_menu_extra(char*alias) {
AXUIElementRefitem=ax_get_extra_menu_item(alias);
if (!item) {
printf("Debug: Menu item not found for alias - %s\n", alias);
return;
}
SLSSetMenuBarInsetAndAlpha(SLSMainConnectionID(), 0, 1, 0.0);
SLSSetMenuBarVisibilityOverrideOnDisplay(SLSMainConnectionID(), 0, true);
SLSSetMenuBarInsetAndAlpha(SLSMainConnectionID(), 0, 1, 0.0);
ax_perform_click(item);
SLSSetMenuBarVisibilityOverrideOnDisplay(SLSMainConnectionID(), 0, false);
SLSSetMenuBarInsetAndAlpha(SLSMainConnectionID(), 0, 1, 1.0);
CFRelease(item);
}
externvoid_SLPSGetFrontProcess(ProcessSerialNumber*psn);
externvoidSLSGetConnectionIDForPSN(intcid, ProcessSerialNumber*psn, int*cid_out);
externvoidSLSConnectionGetPID(intcid, pid_t*pid_out);
AXUIElementRefax_get_front_app() {
ProcessSerialNumberpsn;
_SLPSGetFrontProcess(&psn);
inttarget_cid;
SLSGetConnectionIDForPSN(SLSMainConnectionID(), &psn, &target_cid);
pid_tpid;
SLSConnectionGetPID(target_cid, &pid);
returnAXUIElementCreateApplication(pid);
}
intmain(intargc, char**argv) {
if (argc==1) {
printf("Usage: %s [-l | -s id/alias ]\n", argv[0]);
exit(0);
}
ax_init();
if (strcmp(argv[1], "-l") ==0) {
AXUIElementRefapp=ax_get_front_app();
if (!app) return1;
ax_print_menu_options(app);
CFRelease(app);
} elseif (argc==3&&strcmp(argv[1], "-s") ==0) {
intid=0;
if (sscanf(argv[2], "%d", &id) ==1) {
AXUIElementRefapp=ax_get_front_app();
if (!app) return1;
ax_select_menu_option(app, id);
CFRelease(app);
} else {
ax_select_menu_extra(argv[2]);
}
}
return0;
}
but this is the output im getting :c
Debug: Searching for alias - Owner: Control Center, Name: WiFi
Debug: No matching window found
Debug: Menu item not found for alias - Control Center
while using sketchybar --query default_menu_items i get
ive been loving so far sketchybar, however im trying to toggle the original macos wifi popup, ive read the docs and created this helper (a modified version of the one used in this dotfiles
but this is the output im getting :c
while using
sketchybar --query default_menu_items
i getThe text was updated successfully, but these errors were encountered: