如何点击仅在悬停时可见的按钮?

时间:2015-05-04 11:39:47

标签: macos applescript

我正在修改一个可以清除通知中心通知的AppleScript。此时无法找到一种方法来点击清除按钮

"X" button

您会看到,只有当光标悬停在应用行或下方属于此应用的行时,才会显示该按钮。我这样做:

tell application "System Events" to tell process "SystemUIServer" ¬ 
to click menu bar item "Notification Center" of menu bar 2

tell application "System Events" to tell process "Notification Center" ¬
to value of attribute "AXChildren" of UI element 1 of row 2 of table 1 of ¬
scroll area 1 of window "NotificationTableWindow"

结果:

{static text "iTunes" of UI element "iTunes" of row 2 of table 1 of ¬
scroll area 1 of window "NotificationTableWindow" of application process ¬
"NotificationCenter" of application "System Events"}

但如果我事先策略性地放置光标,我会得到:

{static text "iTunes" of (ditto), button 1 of (ditto)}
我正在寻找

button 1。到目前为止,我尝试了三种无法解决的方法,从愚蠢到不那么愚蠢:

1)键盘导航

我尝试使用key code 125向下导航列表。这不会使按钮可见。在那里,我尝试了无数的删除组合。似乎没有删除通知条目。

来自系统事件的

2)click at (x,y)

在1280x800屏幕上,该按钮的AXFrame为:

{x=1256.00 y=77.00 w=16.00 h=16.00}

给它一个{1264, 85}的中心,所以:

tell application "System Events" to tell process "Notification Center"
click at {1264, 85}
value of attribute "AXChildren" of UI element 1 of row 2 of table 1 of ¬
scroll area 1 of window "NotificationTableWindow"
end tell

毫不奇怪,这并不起作用。

来自系统事件

3)select
tell application "System Events" to tell process "Notification Center" to ¬
tell window "NotificationTableWindow" to tell scroll area 1 to tell table 1 ¬
to tell row 2
select UI element 1
value of attribute "AXChildren" of UI element 1
end tell

尽管如此,我只得到static text 1这是应用名称。 button 1这是明确的按钮无处可寻。

是否有人知道如何点击此按钮 - 仅在悬停时出现的按钮?

1 个答案:

答案 0 :(得分:1)

我无法回答您的问题( GUI脚本,我不是 Yosemite ),但是:

要清除所有通知(适用于 Maverick ,我不知道 Yosemite ),此脚本会在“~/Library/Application Support/NotificationCenter”中删除数据库中的通知文件夹:

set notifCenterFolder to (path to application support from user domain as text) & "NotificationCenter:"
tell application "System Events" to set tDB to POSIX path of (first file of folder notifCenterFolder whose name extension is "db")
do shell script "/usr/bin/sqlite3 " & (quoted form of tDB) & " 'DELETE FROM notifications' && osascript -e 'quit application \"NotificationCenter\" ' && killall usernoted"

-

清除特定应用程序的通知(例如 iTunes ):

set iTunesPath to "/Applications/iTunes.app"
set notifCenterFolder to (path to application support from user domain as text) & "NotificationCenter:"
tell application "System Events" to set tDB to POSIX path of (first file of folder notifCenterFolder whose name extension is "db")
do shell script "/usr/bin/sqlite3 " & (quoted form of tDB) & " 'delete FROM notifications where app_id = (select app_id FROM app_source where last_known_path = \"" & iTunesPath & "\")' && osascript -e 'quit application \"NotificationCenter\" ' && killall usernoted"

-

Yosemite 上,此文件位于另一个文件夹中 - > /var/folder/...this answer

Yosemite

上使用此AppleScript
do shell script "cd `getconf DARWIN_USER_DIR`com.apple.notificationcenter/db/ && /usr/bin/sqlite3 db 'DELETE FROM notifications' && osascript -e 'quit application \"NotificationCenter\" ' && killall usernoted"