With all of the Windows 11 shenanigans of late, I’ve found myself needing to perform bitlocker recovery more often than I would like.
For those of you needing to take something from your clipboard and have it typed out instead of pasted–like for a recovery key into a Windows VM–here is an Automator script which will save you some time. I found this in a GitHub Gist1 so here it is for postarity:
The script
on run
tell application "System Events"
delay 2 # DELAY BEFORE BEGINNING KEYPRESSES IN SECONDS
repeat with char in (the clipboard)
set cID to id of char
if ((cID ≥ 48) and (cID ≤ 57)) then
# Converts numbers to ANSI_# characters rather than ANSI_Keypad# characters
# https://apple.stackexchange.com/a/227940
key code {item (cID - 47) of {29, 18, 19, 20, 21, 23, 22, 26, 28, 25}}
else if (cID = 46) then
# Fix VMware Fusion period bug
# https://apple.stackexchange.com/a/331574
key code 47
else
keystroke char
end if
delay 0.5 # DELAY BETWEEEN EACH KEYPRESS IN SECONDS
end repeat
end tell
end run
How to use
- Launch Automator
- Click Quick Action
- Change “Workflow Receives” to “No Input”
- On the left scroll down and double click “Run AppleScript”
- Erase the Template Text and paste the code above.
- Save the Script
You can now run this action from any application by clicking on the application name from the menu bar > Services > What you named the action.
The first time you run this, it will fail and macOS will ask for Accessability permissions for the application. You will need to grant this and try it again. This will need to be repeated for any application you run it in.
Last note: I changed “delay 0.5” to “delay 0.1” so it didn’t take so long to type out my clipboard. Play around and see what values work best for you.