2

I want to open a document in the current tab in an external application (MacVim for example). Based on a StackOverflow answer I created an Automator service with following AppleScript code:

    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

The issue is, that it opens the file from the first tab and not from the current tab. How can I get the path of the current tab?

0

2 Answers 2

4

Following workaround based on SO answer works for me.

As noted in the comment there: This works EXCEPT if you are using the Assistant editor - then you end up with whatever happens to be in the Standard Editor. – Lloyd Sargent but for me it's better than the first tab.

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

try the following

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.