我想在外部应用程序(例如 MacVim)的当前选项卡中打开文档。基于一个堆栈溢出答案 https://stackoverflow.com/a/12306831/398861我使用以下 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
问题是,它从第一个选项卡而不是当前选项卡打开文件。如何获取当前选项卡的路径?
以下解决方法基于所以答案 https://stackoverflow.com/a/14602063/398861对我有用。
正如评论中指出的:除非您使用助理编辑器,否则这种方法有效 - 那么您最终会得到标准编辑器中的任何内容。 ——劳埃德·萨金特但对我来说,它比第一个选项卡更好。
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)