3

是否可以设置键盘快捷键(或者在某处添加一些菜单项)以在外部编辑器中打开当前编辑的文件?

(显然我可以做[(在文件树中右键单击→在Finder中显示)/(在窗口标题中单击右键→选择包含目录)]→右键单击文件→打开方式→“应用程序”-但步骤太多。 )

4

4 回答 4

10

呵呵,我找到了。

  1. 启动 Automator.app。
  2. 选择“服务”。
  3. 将“运行 AppleScript”拖放到工作流程中。
  4. 将“服务接收”设置为“无输入”,应用程序为Xcode。
  5. 粘贴此代码(用您的编辑器替换 MacVim)

    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
    
  6. 保存工作流程。

  7. 在系统偏好设置 → 键盘 → 键盘快捷键 → 服务 → 常规中,分配一个快捷键。
  8. 你完成了!

我从这个项目中借用了 AppleScript 代码:Uncrustify Automator Services for Xcode 4

于 2012-09-06T19:13:18.897 回答
3

更好的解决方案是直接在键盘首选项窗格中添加键盘快捷键:

  1. 打开“系统偏好设置”→“键盘”→“键盘快捷键”→“应用程序快捷键”
  2. 点击“+”加号
  3. 选择“XCode”作为应用程序并键入“使用外部编辑器打开”作为菜单标题
  4. 设置你的 shourcut(我正在使用 ⇧⌃E)
于 2012-10-02T21:56:37.357 回答
3

因为我使用选项卡,所以我渴望一个不会从第一个选项卡打开文档的解决方案。我最终得到以下结果:

注意:如果打开了助手编辑器,无论哪个编辑器处于活动状态,标准编辑器(左侧)中的文件都会打开,但对我来说它比第一个选项卡更好。

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
于 2014-03-19T17:19:23.720 回答
0

我真的很喜欢Fjölnir提出的解决方案,所以要扩展如何做到这一点。

  1. 选择菜单:“Xcode”->“首选项...”
  2. 单击首选项窗口上的“键绑定”选项卡
  3. 在“过滤器”搜索框中输入External
  4. 双击“使用外部编辑器打开(文件菜单)”命令旁边的“键”列。

键绑定首选项

如果您为此使用 MacVim,则可以通过将外部编辑器配置为在最后一个窗口关闭后保持运行来改善外部编辑器的加载时间。

  1. 选择菜单:“MacVim”->“首选项...”
  2. 在“常规”选项卡中,将“最后一个窗口关闭后”设置为“隐藏 MacVim”

MacVim 设置

现在,当我按下⌥E弹出窗口时,我进行了更改,:q然后焦点返回到 Xcode。

于 2016-07-18T15:01:05.100 回答