0

AppleScript を使用すると、新しく作成されたユーザー作成のコンテンツにアクセスできないことがわかっているので、GUI スクリプトを使用します。しかし、私は 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 を実行できないも参照してください

4

1 に答える 1