Last active
May 30, 2024 10:47
-
-
Save esamattis/288c319992c74ec0114ec56bb8c881cf to your computer and use it in GitHub Desktop.
Type file contents using Apple Script on macOs
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
-- usage: osascript type.scpt <file> | |
on run {filePath} | |
set posixFilePath to filePath | |
set fileContent to do shell script "cat " & quoted form of posixFilePath | |
log "Will start typing in 3 seconds..." | |
delay 3 | |
tell application "System Events" | |
set initialAppName to name of first application process whose frontmost is true | |
beep 1 | |
log "Typing into: " & initialAppName | |
repeat with i from 1 to length of fileContent | |
set currentChar to character i of fileContent | |
set specialChars to {"_", "$", "[", "(", ")", "=", ">", "<", "{", "}", "\"", ";", "]", "'", ":", "/", "`"} | |
if currentChar is in specialChars then | |
set special_char_delay to (random number from 100 to 300) / 1000.0 | |
delay special_char_delay | |
else if currentChar is not equal to " " then | |
set non_space_delay to (random number from 0 to 75) / 1000.0 | |
delay non_space_delay | |
end if | |
keystroke currentChar | |
if currentChar is equal to "`" then | |
key code 49 -- space | |
end if | |
end repeat | |
beep 1 | |
end tell | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You must enable Accessibility for
osascript