Created
February 16, 2012 22:07
-
-
Save DouweM/1848219 to your computer and use it in GitHub Desktop.
Mac AutoTyper
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
display dialog "Enter text to auto type:" buttons {"Cancel", "OK"} default button 2 default answer "" | |
set theResult to the result | |
if the button returned of theResult is "Cancel" then | |
return | |
end if | |
set theText to the text returned of theResult as text | |
if theText is "" then | |
return | |
end if | |
display dialog "Okay! You've got 3 seconds to get the window you want to be auto-typed in to the front." buttons {"OK"} default button 1 | |
delay 3 | |
tell application "System Events" | |
set allLines to my splitString(theText, "\n") | |
set numLines to count of allLines | |
set i to 1 | |
repeat with theLine in allLines | |
set allWords to my splitString(theLine, " ") | |
set numWords to count allWords | |
set j to 1 | |
repeat with theWord in allWords | |
keystroke theWord | |
if j is less than numWords then | |
keystroke " " | |
else | |
if i is less than numLines then | |
key code 36 | |
end if | |
end if | |
set j to j + 1 | |
delay 0.25 | |
end repeat | |
set i to i + 1 | |
end repeat | |
end tell | |
on splitString(theString, theDelimiter) | |
set oldDelimiters to AppleScript's text item delimiters | |
set AppleScript's text item delimiters to theDelimiter | |
set theArray to every text item of theString | |
set AppleScript's text item delimiters to oldDelimiters | |
return theArray | |
end splitString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment