【发布时间】:2021-12-22 14:34:47
【问题描述】:
希望有人能提供帮助 - 我在 Apple M1 Pro 笔记本电脑上运行 macOS Monterey。我的 AppleScript 用于发送存储在 Excel 文件中、通过 Messages 应用程序传递的批量文本消息现在无法正常工作——它在我在 Catalina 下运行的旧笔记本电脑上运行良好。
问题似乎在于将电话号码(“targetBuddyPhone”)传送到消息应用中的正确位置。相反,文本消息(“targetMessage”)被放入应用程序中的收件人位置。有人对可能的解决方案有任何想法吗?
提前致谢。
on run {input, parameters}
set phoneCol to "B"
set messageCol to "C"
set startRow to 1
set counter to "D"
set xlsFilePath to (path to desktop as text) & "texttest.xlsx"
tell application "Microsoft Excel" to open file xlsFilePath
tell application "Microsoft Excel"
set endRow to value of cell (counter & startRow) as number
end tell
repeat with thisRow from startRow to endRow
tell application "Microsoft Excel"
set targetBuddyPhone to string value of cell (phoneCol & thisRow) as string
set targetMessage to value of cell (messageCol & thisRow) as string
end tell
activate application "Messages"
tell application "System Events" to tell process "Messages"
key code 45 using command down -- press Command + N to start a new window
keystroke targetBuddyPhone -- input the phone number
key code 36 -- press Enter to focus on the message area
delay 3
keystroke targetMessage -- type some message
key code 36 -- press Enter to send
end tell
delay 6
end repeat
return input
end run
【问题讨论】:
-
我没有在 macOS Monterey 中设置 Excel 或 Messages,所以我无法测试您的 代码 以查看它失败的确切原因。也就是说,基于 code,显而易见的是,当失败的 code 聚焦时,预期的 UI 元素 没有聚焦。您需要进行一些调试。在制作 ⌘N 之后,您首先需要将焦点设置到正确的 UI 元素。
-
感谢您的评论。您能否指出任何详细说明如何将焦点放在 UI 元素上的资源?
标签: macos applescript sms message macos-monterey