开发者

Make new document in TextMate with rb-appscript or AppleScript?

开发者 https://www.devze.com 2023-01-12 09:51 出处:网络
How do I make a new document in TextMate using rb-appscript or AppleScript? Here is my rb-appscript: te = app(\"TextMate\")

How do I make a new document in TextMate using rb-appscript or AppleScript?

Here is my rb-appscript:

te = app("TextMate")
te.launch
doc = te.make(:new => :document)

But it doesn't work.

Here is the error message I get:

    OSERROR: -10000
    MESSAGE: Apple event handler failed.
    COMMAND: app("/Applications/开发者_JAVA技巧TextMate.app").make({:new=>:document})

If someone gives me an AppleScript code I can convert it to rb-appscript.


Technically, it's supposed to be just this:

tell application "TextMate"
    set theResult to make new document
end tell

But I get the same error in Script Debugger. Creating a new document manually and getting the document via a script works fine. I'm going to say you found a bug in TextMate's Applescript implementation. You could go the GUI scripting route here (shamelessly copied from the Mac OS Automation site):

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
0

精彩评论

暂无评论...
验证码 换一张
取 消