要使用AppleScript读取Dock中应用程序的通知,可以使用以下代码示例:
tell application "System Events"
set dockProcess to first process whose name is "Dock"
tell dockProcess
set dockItems to value of attribute "AXChildren" of list 1
repeat with dockItem in dockItems
tell dockItem
set appName to value of attribute "AXTitle"
set appNotifications to value of attribute "AXNotificationCount"
if appNotifications > 0 then
display notification "Application " & appName & " has " & appNotifications & " notifications."
end if
end tell
end repeat
end tell
end tell
这段代码使用了System Events应用程序来获取Dock的进程,并在循环中检查每个Dock中的应用程序。对于每个应用程序,我们获取应用程序的名称和通知计数。如果通知计数大于0,则显示通知。