Skip to content

Instantly share code, notes, and snippets.

@johnzweng
Last active May 26, 2026 11:34
Show Gist options
  • Select an option

  • Save johnzweng/a7e72610145c7c4e379fc85a35b8512c to your computer and use it in GitHub Desktop.

Select an option

Save johnzweng/a7e72610145c7c4e379fc85a35b8512c to your computer and use it in GitHub Desktop.
make_macgpg_pinentry_focusable

Pinentry-Mac focus fix

Use Homebrew pinentry instead of MacGPG2's

We cannot modify the plist file of MacGPG2 pinentry app because it will break its bunlde's code signature.

# ~/.gnupg/gpg-agent.conf
pinentry-program /opt/homebrew/bin/pinentry-mac

Make pinentry window focusable (remove LSUIElement)

  /usr/libexec/PlistBuddy -c "Delete :LSUIElement" \
    /opt/homebrew/Cellar/pinentry-mac/1.3.1.1/pinentry-mac.app/Contents/Info.plist

Re-sign and restart

  codesign --force --deep --sign - \
    /opt/homebrew/Cellar/pinentry-mac/1.3.1.1/pinentry-mac.app
  gpgconf --kill gpg-agent

│ Note: brew upgrade pinentry-mac will reset the LSUIElement change. │ Re-run the PlistBuddy + codesign steps after upgrades.



All below is obsolete..

UPDATE: this wont work, this breaks of course code signing of the /usr/local/MacGPG2/libexec/pinentry-mac.app App..
codesign --verify --deep --strict /usr/local/MacGPG2/libexec/pinentry-mac.app

DON'T USE THIS!


Pain point

Whenever MacPGP's pinentry UI window pops up it has focus, but if I switch windows (i.e. to my pw manager) I cannot focus back to pinentry using the keyborad only (cannot be selected with cmd+tab).

1. Identify which pinentry GPG actually uses

gpgconf | grep pinentry

Example output:

pinentry:Passphrase Entry:/usr/local/MacGPG2/libexec/pinentry-mac.app/Contents/MacOS/pinentry-mac

Save the .app bundle path (everything up to and including pinentry-mac.app) for the next steps:

PINENTRY_APP="$(gpgconf | awk -F: '/^pinentry:/{print $3}' | sed 's|/Contents/MacOS/.*||')"
echo "$PINENTRY_APP"

2. Check whether LSUIElement is set

/usr/libexec/PlistBuddy -c "Print :LSUIElement" "$PINENTRY_APP/Contents/Info.plist"
  • Prints true → flag is set (focus problem applies)
  • Prints Does Not Exist → nothing to do

What LSUIElement means

LSUIElement (Launch Services UI Element) is an Info.plist flag that tells macOS the app is an "agent" / accessory app:

  • No Dock icon
  • Not in ⌘‑Tab application switcher
  • No menu bar when focused
  • Still can show windows

3. Remove LSUIElement flag

# Backup
sudo cp "$PINENTRY_APP/Contents/Info.plist" "$PINENTRY_APP/Contents/Info.plist.bak"

# Remove the flag
sudo /usr/libexec/PlistBuddy -c "Delete :LSUIElement" "$PINENTRY_APP/Contents/Info.plist"

# Tell LaunchServices to re-read the bundle
sudo /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f "$PINENTRY_APP"
killall cfprefsd 2>/dev/null

# Restart gpg-agent so the next prompt is fresh
gpgconf --kill gpg-agent

4. Test

echo test | gpg --clearsign >/dev/null

Pinentry's window should now appear in ⌘‑Tab and have a Dock icon while open.

⚠️ GPG Suite updates may restore the original Info.plist. Just re‑run step 3 when that happens.

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