XCode 5 - AppleScript - 如何在当前选项卡中获取文档 [英] XCode 5 - AppleScript - How to get document in current tab

查看:24
本文介绍了XCode 5 - AppleScript - 如何在当前选项卡中获取文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在外部应用程序(例如 MacVim)的当前选项卡中打开一个文档.基于 StackOverflow 答案,我使用以下 AppleScript 代码创建了一个 Automator 服务:

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?

推荐答案

以下基于 SO answer 的解决方法对我有用.

Following workaround based on SO answer works for me.

正如那里的评论中所指出的:这有效,除非您使用的是助理编辑器 - 然后您最终会得到标准编辑器中的任何内容.– Lloyd Sargent 但对我来说它比第一个标签更好.

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

这篇关于XCode 5 - AppleScript - 如何在当前选项卡中获取文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆