Skip to content

Comments

Make process name also match bundle name and bundle id#399

Open
einhund wants to merge 1 commit intoasmvik:masterfrom
einhund:master
Open

Make process name also match bundle name and bundle id#399
einhund wants to merge 1 commit intoasmvik:masterfrom
einhund:master

Conversation

@einhund
Copy link

@einhund einhund commented Feb 16, 2026

Useful for precise matching with bundle id, and generic matching with bundle name. Ex: "Web App" matches all web apps added to Dock from Safari.

Full example:

ctrl - j [
  "com.apple.finder" : skhd -k "down"
]
ctrl - k [
  "com.apple.finder" : skhd -k "up"
]
# Web App behaviour fix
cmd - h [
  "web app" : osascript -l JavaScript -e 'ObjC.import("App Kit");$.NSWorkspace.sharedWorkspace.menuBarOwningApplication.hide;'
]
cmd - q [
  "web app" : osascript -l JavaScript -e 'ObjC.import("App Kit");$.NSWorkspace.sharedWorkspace.menuBarOwningApplication.terminate;'
]

I didn't read the full codebase of this project. Thorough code review would be needed.

static inline char *
find_process_bundle_id_for_psn(ProcessSerialNumber *psn)
{
CFDictionaryRef process_info_ref = ProcessInformationCopyDictionary(psn, kProcessDictionaryIncludeAllInformationMask);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we assume this call will never return NULL?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not according to my tests and I can't find any documentation since it's long deprecated. But I'll add checks just to be sure.

{
CFDictionaryRef process_info_ref = ProcessInformationCopyDictionary(psn, kProcessDictionaryIncludeAllInformationMask);
CFStringRef process_bundle_id_ref = CFDictionaryGetValue(process_info_ref, kCFBundleIdentifierKey);
char *process_bundle_id = copy_cfstring(process_bundle_id_ref);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy_cfstring_to_cstring will cause memory leak if it fails.

How are we ensuring it will not return NULL and dereference?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Added checks for null value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants