I want switch from AppCode to Xcode and continue editing file on the same line.
Solution based on UI Automation seems working.
Is the are any solution how to do the same without UI Automation; without need of showing Open Quickly
dialog and typing FileName:LineNumber
?
Thanks!
Solution based on UI Automation.
The code below will open File -> Open Quickly ...
dialog, then will type into File or Symbol
search field and finally will hit 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)
}
Usage from command line:
osascript -l JavaScript "/path/to/openFileInXcode.scpt" "AppDelegate.swift:11"
Usage from AppCode:
- Go to
File -> Preferences -> Tools -> External Tools
- Add new tool and configure parameters using macros (i.e.
$FileName$:$LineNumber$
)
Update 07.06.2016: Detail description of External Tool
setup:
- Program:
/bin/bash
- Parameters:
-c "[[ -r ~/.bashrc ]] && . ~/.bashrc; osascript -l JavaScript \"$PATH_TO_YOUR_SCRIPTS_DIR/OpenFileInXcode.scpt\" \"$FileName$:$LineNumber$\""
- Working directory:
$ProjectFileDir$