【问题标题】:XCode 5 - AppleScript - How to get document in current tabXCode 5 - AppleScript - 如何在当前选项卡中获取文档
【发布时间】:2014-03-19 08:02:14
【问题描述】:
我想在外部应用程序(例如 MacVim)的当前选项卡中打开一个文档。基于StackOverflow answer,我使用以下 AppleScript 代码创建了 Automator 服务:
tell application "Xcode"
set current_document to last source document
set current_document_path to path of current_document
end tell
tell application "MacVim"
activate
open current_document_path
end tell
问题是,它从第一个选项卡而不是当前选项卡打开文件。如何获取当前标签的路径?
【问题讨论】:
标签:
xcode
applescript
xcode5
【解决方案1】:
以下基于SO answer 的解决方法对我有用。
正如评论中所述:这可以工作,除非您使用的是助理编辑器 - 然后您最终会得到标准编辑器中的任何内容。 – Lloyd Sargent 但对我来说它比第一个标签要好。
on run {input, parameters}
set current_document_path to ""
tell application "Xcode"
set last_word_in_main_window to (word -1 of (get name of window 1))
if (last_word_in_main_window is "Edited") then
display notification "Please save the current document and try again"
-- eventually we could automatically save the document when this becomes annoying
else
set current_document to document 1 whose name ends with last_word_in_main_window
set current_document_path to path of current_document
end if
end tell
tell application "MacVim"
if (current_document_path is not "") then
activate
open current_document_path
end if
end tell
return input
end run
【解决方案2】:
试试下面的
告诉应用程序“Xcode”
将文档设置为源文档
如果文档的长度小于 1 则
显示对话框“对于.......我需要至少 1 个文档”
返回
万一
源文档最后一项的路径
结束告诉