Created
March 9, 2021 23:39
-
-
Save dperetti/ebe3995a0dcc52c3239b9937da7e5cf8 to your computer and use it in GitHub Desktop.
xed alternative for CodeStory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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