如何使用rb-appscript或AppleScript在TextMate中创建新文档?
这是我的rb-appscript:
te = app("TextMate")
te.launch
doc = te.make(:new => :document)
但它不起作用。
以下是我收到的错误消息:
OSERROR: -10000
MESSAGE: Apple event handler failed.
COMMAND: app("/Applications/TextMate.app").make({:new=>:document})
如果有人给我一个AppleScript代码,我可以将其转换为rb-appscript。
答案 0 :(得分:3)
从技术上讲,它应该就是这样:
tell application "TextMate"
set theResult to make new document
end tell
但是我在Script Debugger中遇到了同样的错误。手动创建新文档并通过脚本获取文档工作正常。我要说你在TextMate的Applescript实现中发现了一个错误。你可以在这里{GUI}脚本路线(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