Skip to content

Instantly share code, notes, and snippets.

@dperetti
Created Mar 9, 2021
Embed
What would you like to do?
xed alternative for CodeStory
#!/bin/bash
# xed alternative
# xed currently has a tendency to crash or make XCode stall
# for several seconds when it is used to open a file at
# a specific line.
if [ "$1" = "-l" ] || [ "$1" = "--line" ] ; then
line=$2
file=$3
else
line=1
file=$1
fi
# First safely open the file with the shell #j4zTn#
# (using XCodeApp.open($file) yields the same issue as xed)
open -a XCode "$file"
# Then use AppleScript to jump to the specific line
osascript -l JavaScript &>/dev/null <<EOF
var se = Application('System Events')
var XCodeApp = Application('XCODE')
var lineStr = "$line"
XCodeApp.activate()
se.keystroke('l', { using: 'command down' })
for (var i=0; i < lineStr.length; i++) {
se.keystroke(lineStr.charAt(i))
}
se.keyCode(36); // Enter
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment