Skip to content

Instantly share code, notes, and snippets.

@dsample
Last active December 6, 2022 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsample/2d5a226200102de0ad86a26269dd0d42 to your computer and use it in GitHub Desktop.
Save dsample/2d5a226200102de0ad86a26269dd0d42 to your computer and use it in GitHub Desktop.
Mac OSX - Automator - Applescript to type in frontmost application
# Make sure the Yubikey CLI (ykman) is installed
# Replace 'FOO' below with a unique string within the name of one of your keys.
# You can get a list using `ykman oath list`
/usr/local/bin/ykman oath accounts code -s "FOO"
# Add this to a 'Run AppleScript' action within Automator to type the output of a previous step into the frontmost application.
This can be useful for
on run {input, parameters}
tell application "System Events" to tell (process 1 where frontmost is true)
keystroke input
end tell
return input
end run

Automator script to speed up 2FA

If you've got a Yubikey, you can use the Yubico Authenticator to store your 2FA codes. It's able to scan the screen for QRCodes, so you can use it as easily as you can an app on your mobile.

What can make it even faster to use though is to install the CLI (ykman), which can be used to output just the code you need at that moment. If you're on a Mac and create an Automator workflow with the CLI and a bit of AppleScript, you can then use a simple Spotlight search to enter a given code into an app which needs it.

On OSX 10.15 onwards, the first time you run the workflow you'll have give it Accessibility permissions.

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