3

我想从 AppCode 切换到 Xcode 并继续在同一行上编辑文件

基于 UI 自动化的解决方案似乎有效。是否有任何解决方案如何在没有 UI 自动化的情况下做同样的事情?不需要显示Open Quickly对话框和打字FileName:LineNumber

谢谢!


基于 UI 自动化的解决方案。
下面的代码将打开File -> Open Quickly ...对话框,然后输入File or Symbol搜索字段,最后点击Enter

//
// File: openFileInXcode.scpt
//
function run(argv) {
    locationToOpen = argv[0]
    if (locationToOpen == undefined) {
        doSysLog("Nothing to do. Exiting...")
        return
    }
    openFileinXcode(locationToOpen)
}

function openFileinXcode(location) {
    var appXcode = Application('Xcode')
    appXcode.activate()
    doSysLog("Opening file: " + location)
    delay(0.2)

    var appSysEvents = Application('System Events')
    appSysEvents.keystroke('o', { using: ['command down', 'shift down'] })
    appSysEvents.keystroke(location)
    appSysEvents.keyCode(36)
}

function doSysLog(message) {
    app = Application.currentApplication()
    app.includeStandardAdditions = true
    app.doShellScript('syslog -s -l W "WaveLabs Automation: ' + message + '"')
    console.log(message)
}

命令行用法:

 osascript -l JavaScript "/path/to/openFileInXcode.scpt" "AppDelegate.swift:11"

AppCode 的用法:

  1. File -> Preferences -> Tools -> External Tools
  2. 添加新工具并使用宏配置参数(即$FileName$:$LineNumber$

07.06.2016 更新:设置的详细说明External Tool

  • 程序:/bin/bash
  • 参数:-c "[[ -r ~/.bashrc ]] && . ~/.bashrc; osascript -l JavaScript \"$PATH_TO_YOUR_SCRIPTS_DIR/OpenFileInXcode.scpt\" \"$FileName$:$LineNumber$\""
  • 工作目录:$ProjectFileDir$
4

0 回答 0