Not able to Execute AppleScript within “Mail” application

余生长醉 提交于 2019-11-28 04:44:20

问题


I have create one mail plugin and add "Button" beside the "Send" button of outgoing Mail,

and now i want to send outgoing Mail from my Button also and i also write applescript for that like

activate application "Mail"
tell application "System Events"
    tell application process "Mail"
        log "foo"
        tell menu bar 1
            tell menu bar item "Message"
                tell menu "Message"
                    click menu item "Send"
                end tell
            end tell
        end tell
    end tell
end tell

This script is working in Applescript editor but NOT WORKING FROM MY BUTTON CLICK

I have also execute applescript in Xcode like

NSURL* url = [NSURL fileURLWithPath:path];
NSDictionary* errors = [NSDictionary dictionary];    
NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
[appleScript executeAndReturnError:&errors];

And after execute the script i have getting Error:-

NSAppleScriptErrorAppName = "System Events";
NSAppleScriptErrorBriefMessage = "Can't get menu bar 1 of application process \"Mail\". Invalid index.";
NSAppleScriptErrorMessage = "System Events got an error: Can't get menu bar 1 of application process \"Mail\". Invalid index.";
NSAppleScriptErrorNumber = "-1719";
NSAppleScriptErrorRange = "NSRange: {0, 0}";

So I have tried all the thing But not get success.

So PLEASE HELP me to out this Problem

Thanks for any suggestion or help.


回答1:


That menu item does have a keyboard shortcut, so you can use that too. Did you try this?

activate application "Mail"
tell application "System Events"
    tell application process "Mail"
        keystroke "d" using {command down, shift down}
    end tell
end tell


来源:https://stackoverflow.com/questions/13890369/not-able-to-execute-applescript-within-mail-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!