2014-03-19 101 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 
相關問題