如何使用 AppleScript 在 MacOS Big Sur 的 MESSAGES 弹出窗口中单击 'delete' 按钮?

How do I CLICK the 'delete' button in the popup from MESSAGES in MacOS Big Sur using AppleScript?

获取 'delete' 按钮 'clicked' 以响应“消息”应用中下图所示的弹出窗口的简单方法是什么?我尝试了比我愿意承认的更多的变化,我感到很谦卑。

如果我想 'click' 弹出窗口中的 'cancel' 按钮,此代码可以正常工作。

但是我尝试了所有方法都无法单击 'delete' 按钮。

Messages popup after delete message pulldown

tell application "Messages"
    activate
end tell

tell application "System Events"
    key code 2 using command down
end tell


tell application "System Events"
    set frontmost to true
    delay 1
    click button "Cancel"
end tell

这应该适合你。

tell application "System Events" to tell application process "Messages"
    set frontmost to true
    repeat until frontmost
        delay 0.1
    end repeat
    click UI element "Delete" of sheet 1 of window 1
end tell