Thank you everyone, I think I have it working now. Plus, I'll know what to look up in the future, now that I know the mechanism for doing this.On Oct 11, 2014, at 12:38 PM, Bill Cheeseman < email@hidden> wrote:
Scripting the function keys is much trickier, for several reasons. I won't try to list them all here. For example, how you set the "Use all F1, F2, etc. keys as standard function keys" setting in the Keyboard pane of Keyboard preferences in System Preferences makes a big difference. Personally, I always have that setting turned on, meaning that I have to hold down the fn key to use the system functions printed on the function keys. But even then some function keys perform fixed system functions even without holding down the fn key and can't be scripted (for example, F12 opens Dashboard), unless you change those function key assignments in the Shortcuts pane of Keyboard preferences.
That said, the basic idea is to use the System Events 'key code' command. The following script will open Adobe Community Help, because Adobe Reader uses F1 as a keyboard shortcut to open Help.
activate application "Adobe Reader" tell application "System Events" key code 122 -- F1 key end tell
You can look up the key codes on the Web, or you can use any of several utilities that give you the key code for any key you press -- for example, the cleverly named Key Codes application on the Mac App Store. Or you can buy my UI Browser application, which includes a key code lookup drawer and an AppleScript generator that generates 'keystroke' and 'key code' statements, and which includes many other features useful for GUI Scripting in general. < http://pfiddlesoft.com/uibrowser> My recollection is that these key codes may differ on different Mac keyboards and keyboard layouts, but it has been a very, very long time since I read that chapter of Inside Macintosh (although I still have it here on my bookcase, hmm, let's see...). On Oct 11, 2014, at 10:58 AM, Alex Hall < email@hidden> wrote: My only other question is: how do I send F keys? If I use "F5", only the F appears to be sent.
--
Have a great day, Alex Hall
|