jnoortheen / xontrib-cmd-durations

Show long running commands durations in prompt with option to send notification when terminal is not focused.
MIT License
16 stars 4 forks source link

Mac: use `$__CFBundleIdentifier` to detect app window name instead of fixed list #16

Closed anki-code closed 1 year ago

anki-code commented 1 year ago

Example for terminal in VSCode:

# Get current terminal app ("com.microsoft.VSCode")
$__CFBundleIdentifier
# 'com.microsoft.VSCode'

# Get window name for the current terminal app ("Code")
lsappinfo find bundleID=com.microsoft.VSCode
# ASN:0x0-0x32d32d-"Code":

$(lsappinfo find bundleID=com.microsoft.VSCode).split('"')[1]
# 'Code'

lsappinfo | grep -B 1 com.microsoft.VSCode
# 76) "Code" ASN:0x0-0x32d32d:
#    bundleID="com.microsoft.VSCode"

The same is working for any app.

anki-code commented 1 year ago

@jnoortheen what do you think will this work path?

jnoortheen commented 1 year ago

I am not able to find proper documentation for this variable. If it is available we can use from it. Otherwise it will not be able to detect the current app with focus. We will prefer $TERM_PROGRAM over this. If that is not set, the code can use this.

anki-code commented 1 year ago

Here is the doc - https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleidentifier

A bundle ID uniquely identifies a single app throughout the system. The bundle ID string must contain only alphanumeric characters (A–Z, a–z, and 0–9), hyphens (-), and periods (.). Typically, you use a reverse-DNS format for bundle ID strings. Bundle IDs are case-insensitive. The operating system uses the bundle ID to identify the app when applying specified preferences.

It looks useful.