Cocoa应用程序不包含菜单栏,根据的AppleScript [英] Cocoa application contains no menu bars, according to AppleScript

查看:228
本文介绍了Cocoa应用程序不包含菜单栏,根据的AppleScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建本身需要启动一个听写Mac应用程序(OSX 10.8)。因为没有办法开始听写直接要做到这一点的最好办法是通过菜单栏中的编辑/开始听写,因为用户可以有不同的键盘快捷键吧。

I am creating a mac app that needs to start dictation (OSX 10.8) by itself. Because there is no way to initiate dictation "directly" the best way to do this is through the menu bar "Edit"/"Start Dictation" because a user may have different keyboard shortcuts for it.

下面是简单的脚本,我的应用程序调用(使用 NSAppleScript )对象:

Here's the simple script my app calls (using an NSAppleScript object):

tell application "System Events"
    tell application process "MyApp"
        tell menu bar 1
            tell menu bar item "Edit"
                tell menu "Edit"
                    click menu item "Start Dictation"
                end tell
            end tell
        end tell
    end tell
end tell

下面是结果(的NSLog 倒是从AppleScript的错误)

Here are the results (NSLog'd the error from the AppleScript)

Error:-1719 System Events got an error:
Can’t get menu bar 1 of application process "MyApp". Invalid index.

我做了一个基本的测试,看看发生了什么事情。

I did a basic test to see what was going on

我的应用程序:

tell application "System Events"
    tell application process "MyApp"
        set x to menu bars
        return x
    end tell
end tell

result: <NSAppleEventDescriptor: [ ]>

搜索工具:

tell application "System Events"
    tell application process "Finder"
        set x to menu bars
        return x
    end tell
end tell

result: <NSAppleEventDescriptor: [ 'obj '{ 'form':'indx', 'want':'mbar', 'seld':1, 'from':'obj '{ 'form':'name', 'want':'pcap', 'seld':'utxt'("Finder"), 'from':null() } } ]>

所以基本上的AppleScript告诉我我的应用程序没有菜单栏?我跑辅助检查,果然其实也有一个菜单栏(再加上我可以看到它...)。

So basically AppleScript is telling me my app has no menu bars? I run Accessibility Inspector and sure enough there is in fact a menu bar (plus I can see it...).

这是怎么回事错在这里?

What's going wrong here?

推荐答案

我的东西后,相似的,我想激活在Emacs一个服务,它已经以其他方式覆盖全球的键盘快捷键的服务 - 一个不同的问题,我将问另一个线程。

I was after something similar, I wanted to activate a service from within Emacs which had otherwise overridden the global keyboard shortcut to the service - A different question which I will ask in another thread.

运行你的例子上面我也发现,我不得不添加了应用程序(Emacs和测试的Automator),以辅助应用(系统preferences - >安全与隐私权 - >隐私 - >辅助功能)。关于上<进一步信息href=\"http://apple.stackexchange.com/questions/118078/select-a-menu-item-in-applescript-without-using-system-events-in-10-9-maverick\">select-a-menu-item-in-applescript-without-using-system-events-in-10-9-maverick也的AppleScript - uiscripting

Running your examples above I did discover that I had to have added the application (Emacs and for testing Automator) to the Accessibility applications (System Preferences -> Security & Privacy -> Privacy -> Accessibility). Further information regarding that on select-a-menu-item-in-applescript-without-using-system-events-in-10-9-maverick and also AppleScript - uiscripting.

随着地方访问,我能看到在服务菜单项:

With that access in place I am able to see the menu items under services:

tell application "Emacs"
    activate
end tell
tell application "System Events"
    tell application process "Emacs"
        tell menu bar 1
            tell menu "Emacs"       
                tell menu item "Services"
                    tell menu "Services"
                        set x to menu items
                        click menu item "XXX"
                        return x
                    end tell
                end tell
            end tell
        end tell
    end tell
end tell

但动作没有被激活!

But the action is not activated!

使用错误上面的例子则返回'XXX'不存在。用正确的字符串替换字符串表示没有发生错误,但动作不会发生。

Using the example above an error is returned that 'XXX' does not exist. Replacing the string with the correct string means no error occurs, but the action does not take place.

这篇关于Cocoa应用程序不包含菜单栏,根据的AppleScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆