AppleScript tip: simulating the Enter key

By Alvin J. Alexander, devdaily.com

When I created my AppleScript program to open a list of URLs in Safari I needed a way to type the URLs into Safari. That turned out to be pretty easy, I did it like this:

keystroke "http://www.apple.com/"

The much harder part was figuring out how to simulate typing the Enter (or Return) key from AppleScript. Without further ado, here's the answer:

-- simulate pressing the Enter key
key code 36

I found this answer by downloading a program named Full Key Codes. It's a simple program that shows the codes for the keys as you press them on your keyboard.


devdaily logo