937 views
<center> # How to remap a Mac's power button to help fill system password prompts using 1Password *Originally published 2019-12-11 on [docs.sweeting.me](https://docs.sweeting.me/s/blog).* <em>Autofill prompts that don't natively support 1Password or Touch-ID with two keystrokes.</em> <img src="https://docs.monadical.com/uploads/upload_b6d4c1f8c2af9ab46794b885eaa78358.png" style="width: 10%; margin-bottom:-50px; margin-left: 130px"> <img src="https://docs.monadical.com/uploads/upload_4374d5f408024208719815a8d8c451cd.png" style="width: 30%">» <img src="https://docs.monadical.com/uploads/upload_54c153e11000e8c272b711e4b1bd3b86.png" style="width: 70px; margin-right: -7px">/ &nbsp;<img src="https://docs.monadical.com/uploads/upload_86c701915f5761ed6c8e3215092aa598.png" style="width: 40px">&nbsp;&nbsp;, &nbsp; `Ctrl + V` &nbsp; »<img src="https://docs.monadical.com/uploads/upload_513216961870a68481971cc8eca8fd27.png" style="width: 30%"><hr/> </center> ## Intro In this modern age of TouchID, FaceID, 2FA, etc. have you ever been annoyed at how often you still have to type your system password? It turns out you can script the power button on macOS to trigger a relatively safe password input by using 1Password's built-in Autofill and "Copy to clipboard" features. --- [TOC] --- ## Security Considerations - Storing passwords in the clipboard isn't great, this should only be used as a last resort for applications that don't support 1password autofill natively. - Anything that can read your clipboard can see the password whenever you use this shortcut - Anyone who can trigger keypresses on your computer (whether via scripted event or physical button) can load your password into the clipboard with one keypress. - It relies on your 1password vault already being unlocked, e.g. via Master Password or Touch ID Since the power button is only automating the process of searching for the password in 1Password, it's not actually storing or comparing any secrets itself. It doesn't need a keychain and it doesn't need sudo, and as a consequence it wont work if your 1Password vault is locked. --- ## Setup Steps #### 1. Set 1password to open with a keyboard shortcut &nbsp; <blockquote style="display: inline">e.g. `⌘ + .`</blockquote> We're going to create an AppleScript that uses this command to trigger 1password later on. <img src="https://docs.monadical.com/uploads/upload_45cc9eb14f343d59d263572590fada4a.png" width="30%"/> #### 2. Create a password with a unique title in 1Password &nbsp; <blockquote style="display: inline">e.g. `q-2vn94d1f`</blockquote> For speed reasons, the title's first 2 characters should not overlap with any other passwords. It's helpful to use special characters like `<>?/.!@#$%^&*` since password titles rarely start with those. We want it to pop up to the top with minimal automated keystrokes needed. <img src="https://docs.monadical.com/uploads/upload_5624cb51e5fb1f284224d76dec02355a.png" width="30%"/> #### 3. Download `PowerKey.app` (needed to map the power button to an arbitrary script) - It can be purchased here: https://gumroad.com/l/powerkey($5) - Or built from source: https://github.com/pkamb/PowerKey ($0 <img src="https://docs.monadical.com/uploads/upload_669dcd14a8bd82319f21320b84c13f9d.png" width="25%"/><img src="https://docs.monadical.com/uploads/upload_7f7a816d97a29e5eb791952d1ea646f1.png" width="26%"/> &nbsp; or <img src="https://docs.monadical.com/uploads/upload_e8e99a6ba74520321baf33df33d23e9b.png" width="30%"/> #### 4. Create `power_button_shortcut.scpt` in `Script Editor.app` <img src="https://docs.monadical.com/uploads/upload_efaa9a5f6280667e1a50acef7fd5059e.png" width="70%"/> #### 5. Edit the script to use 1password keyboard and select your password. It just needs to type enough letters of the password title to select it uniquely, not the full title. You can lookup any keycodes needed on [eastmanreference.com](https://eastmanreference.com/complete-list-of-applescript-key-codes), then update the script, e.g. > For example: > *Trigger 1Password:* `⌘ + .` == `key code 47 using command down` > *Find password:* `q-2vn94d1f` == `keystroke "q-2vn"` **`power_button_shortcut.scpt`:** ```haskell tell application "System Events" -- Press "⌘ + ." to open 1password search prompt key code 47 using command down -- A tiny delay is needed for it to load, raise this if your computer is slow delay 0.125 -- Type the fewest keystrokes needed to search for the password we want to copy keystroke "q-2vn" -- Wait a split-second for it to finish filtering and highlight the matching password delay 0.1 -- Press "Cmd + Shift + C" to copy the selected password to clipboard keystroke "c" using {command down, shift down} end tell ``` #### 6. Set `PowerKey.app` to run the script when the power button is pressed <img src="https://docs.monadical.com/uploads/upload_d8b7dc04fc0efdf783b60269de357786.png" width="30%"> #### 7. Press the power button, you should see a notification once it's been copied to clipboard. Paste the password somewhere to use it, then 1Password should auto-clear the clipboard after use or in 60 seconds (configurable in 1Password preferences). <center><em>Power button -> <code>power_button_shortcut.scpt</code> -> 1Password -> Clipboard</em><br/><br/><img src="https://docs.monadical.com/uploads/upload_585d651647ba47eaf67ffc782f2e3478.png" style="width: 40%;vertical-align:top"> ➡️ <img src="https://docs.monadical.com/uploads/upload_5718a2b313b45fcfba26ad85796af897.gif" style="width: 40%;vertical-align: -280px"> </center>