如何单击仅在悬停时可见的按钮?
How to click a button that's only visible when hovered over?
我正在修改一个可以清除通知中心通知的 applescript。此时无法找到单击 清除按钮.
的方法
你看,只有当光标悬停在应用程序所在的行或属于该应用程序的行下方时,才会出现该按钮。我愿意:
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
那个清除按钮无处可寻。
有谁知道如何点击这个按钮 - 一个只有悬停时才会出现的按钮?
我无法回答你的问题(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"
我正在修改一个可以清除通知中心通知的 applescript。此时无法找到单击 清除按钮.
的方法你看,只有当光标悬停在应用程序所在的行或属于该应用程序的行下方时,才会出现该按钮。我愿意:
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
那个清除按钮无处可寻。
有谁知道如何点击这个按钮 - 一个只有悬停时才会出现的按钮?
我无法回答你的问题(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"