首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用rb-appscript或AppleScript在TextMate中创建新文档?

使用rb-appscript或AppleScript在TextMate中创建新文档?
EN

Stack Overflow用户
提问于 2010-08-23 00:52:08
回答 1查看 661关注 0票数 0

如何使用rb-appscript或AppleScript在TextMate中创建新文档?

下面是我的rb-appscript:

代码语言:javascript
复制
te = app("TextMate")
te.launch
doc = te.make(:new => :document)

但它不起作用。

下面是我得到的错误消息:

代码语言:javascript
复制
    OSERROR: -10000
    MESSAGE: Apple event handler failed.
    COMMAND: app("/Applications/TextMate.app").make({:new=>:document})

如果有人给我一个AppleScript代码,我可以把它转换成rb-appscript。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-08-23 02:22:21

从技术上讲,它应该是这样的:

代码语言:javascript
复制
tell application "TextMate"
    set theResult to make new document
end tell

但是我在脚本调试器中得到了同样的错误。手动创建新文档并通过脚本获取文档效果良好。我要说你在TextMate的Applescript实现中发现了一个bug。您可以在此处使用图形用户界面脚本( (shamelessly copied from the Mac OS Automation site):

代码语言:javascript
复制
return do_menu("TextMate", "File", "New")
--> result: true and a window appeared in TextMate

on do_menu(app_name, menu_name, menu_item)
    try
        -- bring the target application to the front
        tell application app_name
            activate
        end tell
        tell application "System Events"
            tell process app_name
                tell menu bar 1
                    tell menu bar item menu_name
                        tell menu menu_name
                            click menu item menu_item
                        end tell
                    end tell
                end tell
            end tell
        end tell
        return true
    on error error_message
        return false
    end try
end do_menu
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3542363

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档