Trying to paste clipboard info into TextEdit
I am new to AppleScript, but from what I've been reading, this should a fairly simple task. I'm trying to do the following:
- Create a new TextEdit document
- Paste the contents fo the clipboard into the document
Current system configuration:
- iMac with an Intel Core i5
- OS X 10.8
- "Enable access for assistive devices" in System Preferences is checked.
This is the code I am using:
tell application "TextEdit"
activate
tell application "System Events"
tell process "TextEdit" to keystroke "V" using {command down}
end tell
end tell
The code compiles without any issues. When I run the scrip in AppleScript Editor, it starts TextEdit and then I hear a beep. When I export the script as an application and run it, TextEdit starts, I do not hear a beep, but no text is pasted. I appears that the TextEdit program does not have the focus when the paste command attempts to run.
Any help would be greatly appreciated!
OS X Mountain Lion (10.8)