0
我知道使用AppleScript無法訪問新創建的用戶寫入內容,因此我使用GUI腳本。但是我希望Mail.app包含自己的按鈕,該按鈕已添加到我從所需目錄發送的新創建的文件中。我有一個Mail.app的插件,有一個腳本被我自己的按鈕調用。該腳本獨立運行奇蹟,但在從插件調用時不起作用。我究竟做錯了什麼?AppleScript自行創作奇蹟,但從插件調用時不起作用
錯誤
{
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也看到Not able to Execute AppleScript within "Mail" application