applescript - 如何与applescript中的“消息”进行交互
问题描述
我正在尝试制作一个应用程序来自动化 Mac 上的 Messages 应用程序。其中一项自动化需要与对话信息按钮进行交互。我试图编写一个脚本来开始使用它:
tell application "System Events"
tell process "Messages"
set infoButton to "Conversation Details"
click toolbar item infoButton of toolbar 1
end tell
end tell
但是我收到错误:错误System Events got an error: Can’t get item \"Conversation Details\" of process \"Messages\"." number -1728 from item "Conversation Details" of process "Messages
下面我粘贴了使用辅助功能检查器的屏幕截图,其中包含我试图操作的 ui 元素周围的信息。任何帮助将不胜感激。
解决方案
如果您尝试 使用AppleScript单击macOS Big Sur中消息工具栏上的对话详细信息 按钮,则以下示例AppleScript代码将执行此操作:
tell application "System Events" to ¬
if exists (buttons of ¬
toolbars of ¬
front window of ¬
process "Messages" whose ¬
description is "Conversation Details") ¬
then click (buttons of ¬
toolbars of ¬
front window of ¬
process "Messages" whose ¬
description is "Conversation Details")
简而言之,就是:
button 2 of toolbar 1 of window 1 of application process "Messages"
但是,我更喜欢用错误处理方法来编写它,就像上面显示的完整tell
语句一样。
推荐阅读
- google-maps - 使用 Google Maps API 显示 SVG 叠加层的优化建议
- c# - 使用 dotNetRDF 的 SPARQL 查询返回正确数量的结果但值为空,为什么?
- java - 针对代码失败的测试用例改进代码
- c++ - C++ 函数可以返回一个指向已知长度数组的指针吗?
- javascript - 如何使用下拉列表对单选按钮进行逻辑分组
- android - 如何在所有应用程序依赖项中仅使用 Android 21?
- c# - 为什么强内存模型不会阻止 cpu 缓存?
- c# - 使用泛型类型 'IdentityUserRole
' 需要 1 个类型参数 - c++ - 在O(nlogn)中对数组进行排序的第一个元素插入数?
- machine-learning - 随机森林回归不给出 0 或 1