NSLogger
NSLogger copied to clipboard
Jump into XCode to log emitting line
May I remember the 'jump to code' feature ;) It was part of this ticket. https://github.com/fpillet/NSLogger/issues/closed#issue/10
I think it should be a straight forward implementation using some Apple Script magic. Maybe someone who knows Apple Script better than me could prepare the code to be used in NSLogger?
Would be great if I could have double click on a log entry to jump to the code. Maybe worth a settings option to let the user choose if he prefers jump to code or logging details?
I don't forget about you ... I just didn't have the time to do it yet -- need to intercept mouve clicks in the cell and over the filename/function line and call the xed command line to open the file. Will do soon :-)
As to differentiating simple and double clicks, that's relatively easy - there is a flag for that in events.
Sorry, I didn't want to urge you :)
Maybe it could be added as a button to the details window as a first step.
But I don't need the detail window at all, therefore it would be also ok for me to get into the code on double click directly ;)
Argh... by accident I closed this ticket. I think only you can reopen it again. Sorry.
Congratulations to 1.0 release. I would really love to see this feature in NSLogger though. I made some investigation and you can use the following XCode command line tool to jump to a file and line:
xed --line 100 ~/work/xyz/MainWindowController.m
It should be very straight forward to implement this feature e.g. using NSTask to call this. It seems that XCode is entelligent enough to open the correct Workspace or Project.
I pushed an experimental implementation to the 'development' branch. Alt-doubleclick to open the file in Xcode. Unfortunately, xed doesn't seem to direct Xcode to select the proper line (there's an OSA error, try it in console with the same arguments to see it).
If you want to help refine the implementation, look at -logCellDoubleClicked: in LoggerWindowController.m. Ultimately, what I want is an arrow that shows up when you hover a log entry that has a valid filename attached to it. Lacking the time to implement this, though.
Indeed. I have no idea how to solve it. I posted a question to StackOverflow where hopefully some genius may help us out with a solution. http://stackoverflow.com/questions/7957016/jump-to-file-and-line-from-outside-xcode-4-2
Thanks for implementing the stuff so far.
Bug reported to Apple as rdar://10626303 - See a copy of it at http://openradar.appspot.com/radar?id=1480404
If you want to you could replace xed with the following shell/applescript combo:
#!/bin/bash
if [ "$1" = "-l" ] || [ "$1" = "--line" ] ; then
line=$2
file=$3
else
line=1
file=$1
fi
osascript &>/dev/null <<EOF
tell application "Xcode"
open "$file"
activate
tell application "System Events"
tell process "Xcode"
keystroke "l" using command down
repeat until window "Jump" exists
end repeat
click text field 1 of window "Jump"
set value of text field 1 of window "Jump" to "$line"
keystroke return
end tell
end tell
end tell
EOF
Warning:
- no error checking,
- crude commandline parsing
- not the full functionality of the original xed
- "Jump in 'filename.m'" in the "Navigate" Menu in Xcode must have command+L as shortcut
- Universal Access has to be turned on for this to work
Awesome! The open line did not work for me and since I'm not very good at AppleScript I made a little workaround ;)
#!/bin/bash
if [ "$1" = "-l" ] || [ "$1" = "--line" ] ; then
line=$2
file=$3
else
line=1
file=$1
fi
xed "$file"
osascript &>/dev/null <<EOF
tell application "Xcode"
activate
tell application "System Events"
tell process "Xcode"
keystroke "l" using command down
repeat until window "Jump" exists
end repeat
click text field 1 of window "Jump"
set value of text field 1 of window "Jump" to "$line"
keystroke return
end tell
end tell
end tell
EOF
Fantastic! Thanks guys - BTW I'm now using AppCode most of the time instead of Xcode, which starts sucking balls. Need to find a way to do this for AppCode too :-)
Thanks for the awesome script, will get this integrated in NSLogger ASAP.
if you omit the "open" thing, it jumps to the line in the current open file in Xcode so that would not be wise to do.
Perhaps that's some file name quoting issue, if i hit the problem too i'll update.
Current Code in this gist: https://gist.github.com/2250729
Indeed, your script works perfectly. The problem was that I did not use an absolute file path. Sorry, my fault. This will be a killer feature for NSLogger :)
I added the feature from the development branch again. So far it seems to work fine. On ALT + Double Click it jumps into Xcode. It just does not show the cursor or hilite the line somehow, but this may just be little tweaks in the Apple Script. Hope you like it: https://github.com/holtwick/NSLogger/commit/22e21507bd569edb066a596be885aca43b42b633
That's a really nice future. Great job guys.
I noticed two bugs though:
- I have several osascript processes running on my machine after using the feature
- Double-clicking does not always do what expected: sometimes the "Jump" stays open, sometimes I have line of code deleted, sometimes it does not jump to the line. I guess this is a "synchronization" problem.
I had a rapid look into it but did not find any solution for now.
thanks, guys! this is great, much appreciated.
one note, in case it helps anyone else: i have a global key binding for Command-L, so the keystroke "l" using command down AppleScript didn't work for me. I replaced it with click menu item index 36 of menu "Navigate" of menu bar item "Navigate" of menu bar 1. Works in Xcode 4.6. It'll need to be updated if/when the Navigate menu changes, or replaced with something that iterates through the menu items and checks for the "Jump in " substring, but it works for me for now.
I optimized this script to make it get to the line in the source file much faster. It could probably use some fallback logic in case for some reason you don't already have the project open (though.. that's what mainly seemed to slow everything down...)
Code is here → Made "⌥ + double click" Open Quickly
awesome, thanks!
I also realized that some of the weird behavior people may have been noticing with this is most likely caused by having to press ⌥ when double clicking: if you don't let go of the ⌥ key pretty darn fast, then it can interfere with the AppleScript keystroke commands, resulting in Xcode not doing what you want it to do.
Code that I think addresses this issue: https://github.com/fpillet/NSLogger/pull/102
For whoever may be interested, I came up with what I think are some more improvements: https://github.com/fpillet/NSLogger/pull/114