我想在外部应用程序(例如 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
问题是,它从第一个选项卡而不是当前选项卡打开文件。如何获取当前标签页的路径?
最佳答案
以下解决方法基于 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
关于XCode 5 - AppleScript - 如何在当前选项卡中获取文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22499621/