13.10. GUI Scripting
GUI Scripting gives you the ability to script almost any application on the Mac. It does this by mimicking the actions of clicking the mouse, selecting menu items, and typing keystrokes. The next Try It Out gives you a quick look at how to use this technique for scripting applications.
13.10.1.
13.10.1.1. Try It Out: Introduction to GUI Scripting
This program shows how you can copy the text inside your TextEdit window to your application without knowing the specific AppleScript command to do this. You saw how to use the clipboard commands earlier in this chapter to accomplish this; these steps provide another approach.
Select System Preferences from the Apple Menu.
In the System Preferences window, click the icon labeled Universal Access.
Check Enable Access for Assistive Devices. Enter your administrative password when prompted.
Close the System Preferences window.
Launch the TextEdit application.
Type some lines of text into the TextEdit Window.
Type the following program into Script Editor:
-- Copy the text from TextEdit's window to the clipboard tell application "System Events" tell application process "TextEdit" set frontmost to true click menu item "Select All" of menu "Edit" of menu bar item "Edit" ¬ of menu bar 1 click menu item "Copy" of menu "Edit" of menu bar item "Edit" of menu bar 1 end tell end tell delay 1 the clipboardClick the Result tab and run the program. The text from the web page you loaded should be displayed in the Result pane.
13.10.1.2. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access