Created
December 14, 2020 19:49
-
-
Save WestonThayer/a154d0879e5bfa869f98166c5a3761c9 to your computer and use it in GitHub Desktop.
MacOS Automator AppleScript for typing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using MacOS Automator to type in any application. Useful for | |
# apps that don't support pasting | |
# | |
# To configure: | |
# | |
# 1. Open Automator | |
# 2. Create a new Quick Action (formerly known as a Service) | |
# 3. Workflow receives: no input | |
# 4. in: any application (you may need to grant Automator Accessibility | |
# access in System Preferences) | |
# 5. Drag a Run AppleScript action onto the canvas and paste the below | |
# 6. Modify the cmd string to whatever you want to type. Make sure you | |
# escape " and \ | |
# 7. Click the run button, then switch to the target application | |
# https://eastmanreference.com/complete-list-of-applescript-key-codes | |
on type_code(keycode) | |
tell application "System Events" | |
key code keycode | |
end tell | |
end type_code | |
on type_char(char) | |
tell application "System Events" | |
keystroke char | |
end tell | |
end type_char | |
on type_paste(cmd) | |
repeat with char in cmd | |
set charS to (char as string) | |
if charS is equal to "." then | |
type_code(47) | |
else if charS is equal to "1" then | |
type_code(18) | |
else if charS is equal to "2" then | |
type_code(19) | |
else if charS is equal to "3" then | |
type_code(20) | |
else if charS is equal to "4" then | |
type_code(21) | |
else if charS is equal to "5" then | |
type_code(23) | |
else if charS is equal to "6" then | |
type_code(22) | |
else if charS is equal to "7" then | |
type_code(26) | |
else if charS is equal to "8" then | |
type_code(28) | |
else if charS is equal to "9" then | |
type_code(25) | |
else if charS is equal to "0" then | |
type_code(29) | |
else | |
type_char(char) | |
end if | |
delay 0.05 | |
end repeat | |
end type_paste | |
on run {input, parameters} | |
delay 3 | |
set cmd to "Some text" | |
type_paste(cmd) | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment