2014-03-19 78 views
1

我想在外部应用程序(例如MacVim)的当前选项卡中打开文档。根据StackOverflow answer我创建了一个Automator的服务,下面的AppleScript代码:XCode 5 - AppleScript - 如何在当前选项卡中获取文档

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 

的问题是,它从第一选项卡中打开该文件,而不是从当前选项卡。我怎样才能获得当前标签的路径?

回答

3

以下解决方法基于SO answer适合我。

正如在评论中指出的那样:这是行之有效的,如果您使用的是助手编辑器 - 那么您最终会遇到在标准编辑器中发生的任何事情。 - 劳埃德萨金特但对我来说,它比第一个标签更好。

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 
1

尝试以下

 
tell application "Xcode" 
    set docs to source documents 
    if length of docs is less than 1 then 
     display dialog "for ....... I need at least 1 document" 
     return 
    end if 
    path of last item of source documents 
end tell 
相关问题