There are numerous ways to refer to objects within the object hierarchy: name is only one way (see AppleScript Language Guide: Reference Forms. Your script already uses one of the other ways: Index.
tell menu bar 1
这份索引提到菜单:(与许多方案语言一样,阿普兰文清单中的项目从1个而不是0个指数化)。 下面的文字应当满足你们的愿望:
tell application "Twitter" to activate
tell application "System Events"
tell application process "Twitter"
click menu item "Empty Cache" of menu "Twitter" of menu bar item "Twitter" of menu bar 1
delay 1
--click button "Empty Cache" of front window
click button "Empty Cache" of window 1
end tell
end tell
tell application "Twitter"
quit
delay 1
activate
end tell
您也许可以评论<代码>delay 1的行文;我补充说,这些行文使程序放慢,使你能够更容易地看到所发生的情况。
When trying to figure out how to "get at" an object in an application via AppleScript, I often find it helpful to use AppleScript Editor to create little query scripts to try to discover more info about the app. For example, in Twitter, I chose Twitter > Empty Cache to bring up the Empty Cache window. I then ran the following script:
tell application "Twitter"
set theWindows to every window -- get a list of windows
(* turns out there s only one window listed,
so get the first item in the list *)
set theWindow to first item of theWindows
-- get the properties of the window
properties of theWindow
end tell
该书还得出以下结果:
{closeable:true, zoomed:false, class:window, index:1,
visible:true, name:missing value, miniaturizable:true,
id:28551, miniaturized:false, resizable:true,
bounds:{-618, 76, -128, 756}, zoomable:true}