Skip to content

Instantly share code, notes, and snippets.

@akhoury6
Created May 19, 2016 15:23
Show Gist options
  • Save akhoury6/afe2e6aeb17ed8f53669dd352836abbf to your computer and use it in GitHub Desktop.
Save akhoury6/afe2e6aeb17ed8f53669dd352836abbf to your computer and use it in GitHub Desktop.
Generate an MFA token with an OS X Keyboard Shortcut
-- Settings
set mfaSecret to "<token>"
-- Install oath-toolkit if not available
try
do shell script "which /usr/local/bin/oathtool"
on error
display dialog "This script needs to install oath-toolkit. Please ensure that brew is installed, then hit OK to continue."
do shell script "brew install oath-toolkit"
end try
-- Generate key
set generated_key to do shell script "/usr/local/bin/oathtool --totp -b " & mfaSecret
set the clipboard to generated_key
-- Paste into Application
tell application "System Events"
keystroke generated_key
end tell
@akhoury6
Copy link
Author

This script allows you to generate an MFA token with an OS X keyboard shortcut. It is tested to work with AWS.

Installation
  1. Open Automator on your mac and create a new Service
  2. Add an Applescript action
  3. Paste the code into the dialog box, specifying your mfaSecret at the top
  4. At the top of the window, set the service to receive no input in any application
  5. Save the Service as MFA Token
  6. Under System Preferences -> Keyboard -> Shortcuts you will now see the MFA Token service. Assign the keyboard shortcut of your choice.
Usage

Use the keyboard shortcut to have a token typed into the active text area in any application.

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