我知道使用 AppleScript 无法访问新创建的用户编写的内容,所以我使用 GUI Scripting。但我希望 Mail.app 包含自己的按钮,该按钮已添加到我从所需目录发送的新创建文件中。我有一个 Mail.app 插件有一个由我自己的按钮调用的脚本。该脚本本身可以创造奇迹,但从插件调用时它不起作用。我究竟做错了什么?
错误
{
NSAppleScriptErrorAppName = "System Events";
NSAppleScriptErrorBriefMessage = "System Events get error: Can not catch window 1 of process "Mail". Wrong index.";
NSAppleScriptErrorMessage = "System Events get error: Can not catch window 1 of process "Mail". Wrong index.";
NSAppleScriptErrorNumber = "-1719";
NSAppleScriptErrorRange = "NSRange: {0, 0}";
}
和脚本
property theMessage : ""
property allMessages : ""
property myPath : ""
property mySubfolder : "prettyAttachment"
tell application "AppleScript Utility"
set GUI Scripting enabled to true
end tell
tell application "Mail"
try
set allMessages to outgoing messages
set theMessage to front outgoing message
end try
if theMessage is not equal to "" then
tell application "Finder"
activate
set myPath to quoted form of POSIX path of ((path to downloads folder as string) & mySubfolder)
set shellScriptText to "open " & myPath
do shell script shellScriptText
tell application "System Events"
keystroke "a" using command down
keystroke "c" using command down
keystroke "h" using command down
end tell
end tell
activate --mail.app
tell application "System Events"
tell process "Mail"
--?set visible to true
set allUI to every UI element of front window
end tell
repeat with anUI in allUI --as list
set theRole to role of anUI
if theRole is equal to "AXScrollArea" then
set allSubUi to UI elements of anUI
if (count of allSubUi) is equal to 2 then
--set focused of anUI to true
set value of attribute "AXFocused" of anUI to true
tell application "System Events"
keystroke "v" using command down
return true
end tell
end if
end if
end repeat
end tell
end if
end tell
因此,为了进行测试,您可以将一些文件添加到prettyAttachment
下载文件夹中的文件夹 -> 打开 Mail.app 并创建消息 -> 启动脚本
但是为什么脚本在 xCode 包中不起作用?问候并希望得到帮助。
EDIT1还看到无法在“邮件”应用程序中执行 AppleScript