Skip to content

Instantly share code, notes, and snippets.

@dperetti
Created March 9, 2021 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dperetti/ebe3995a0dcc52c3239b9937da7e5cf8 to your computer and use it in GitHub Desktop.
Save dperetti/ebe3995a0dcc52c3239b9937da7e5cf8 to your computer and use it in GitHub Desktop.
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