加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xcode – 无法在“Mail”应用程序中执行AppleScript

发布时间:2020-12-14 19:22:52 所属栏目:百科 来源:网络整理
导读:我创建了一个邮件插件,并在外发邮件的“发送”按钮旁添加“按钮”, 现在我想从我的按钮发送传出的邮件,我也写了这样的AppleScript activate application "Mail"tell application "System Events" tell application process "Mail" log "foo" tell menu bar 1
我创建了一个邮件插件,并在外发邮件的“发送”按钮旁添加“按钮”,

现在我想从我的按钮发送传出的邮件,我也写了这样的AppleScript

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

这个脚本在Applescript编辑器中工作,但不是从我的按钮点击工作

我也在Xcode中执行applescript

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

执行脚本后我得到错误: –

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}";

所以我已经尝试了所有的东西但是没有获得成功.

请帮助我解决这个问题

感谢您的任何建议或帮助.

解决方法

该菜单项具有键盘快捷键,因此您也可以使用它.你试过这个吗?

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读