从AppCode打开FileName:Xcode中的LineNumber

时间:2015-02-21 02:03:45

标签: xcode app-code appcode javascript-automation

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

基于UI Automation的解决方案似乎有效。 没有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$
  3. 更新07.06.2016 External Tool设置的详细说明:

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

0 个答案:

没有答案