XCode 5 - AppleScript - 如何在当前选项卡中获取文档

标签 xcode applescript xcode5

我想在外部应用程序(例如 MacVim)的当前选项卡中打开文档。基于 StackOverflow answer我使用以下 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

问题是,它从第一个选项卡而不是当前选项卡打开文件。如何获取当前标签页的路径?

最佳答案

以下解决方法基于 SO answer为我工作。

如那里的评论所述:如果您使用的是辅助编辑器,则此方法有效 - 然后您最终会得到标准编辑器中的任何内容。 – Lloyd Sargent 但对我而言,它比第一个选项卡更好。

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 - 如何在当前选项卡中获取文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22499621/

相关文章:

iPhone 屏幕截图错误。 <错误> : ImageIO: CGImageDestinationFinalize image destination does not have enough images

objective-c - 以编程方式在另一个桌面(空间)中打开 NSWindow

macos - 从 shell 调用 Finder 的 "Import from iPhone > Take Photo"

applescript,将文件夹及其内容移至垃圾箱

terminal - 在 Mac OS X Yosemite 上切换隐藏/显示隐藏文件的最快方法是什么?

ios - 架构arm64的 undefined symbol

ios - 进入调试器时出现 EXC_BAD_ACCESS(代码=1,地址=0x0)

ios - 远程数据加载后 swift alamofire show viewcontroller

ios - 将 ImageView 放入 Collection View 单元格导致 IBTool 发出警告

c++ - STL for_each 无法在 Xcode 中使用 map