What this does:
Enables you to externally open a specific file in eclipse, and go to some line
That is clicking on the following link:
openineclipse://open?url=file:///etc/hosts&line=3
Will open /etc/hosts file and go to line 3
if you have a pretty standard setup you can probably just download OpenInEclipse.app.zip , unzip and place in /Applications
How to create this:
open AppleScript Editor and paste
on open location this_URL
### constants
set path_to_eclipse to "/Applications/eclipse/Eclipse.app"
set sleep_before_going_to_line to "0.5" # in seconds
### parse url
set line_number_starts to offset of "&" in this_URL
set filename to text ((length of "openineclipse://open?url=file://") + 1) thru (line_number_starts - 1) of this_URL
set line_number to text ((length of "line=") + line_number_starts + 1) thru -1 of this_URL
#display alert "DEBUG: file " & filename & " line " & line_number
### open the file in eclipse
set openCmd to "open -a " & path_to_eclipse & " '" & filename & "'"
do shell script openCmd
### go to line via keyboard shortcuts
# because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=305336
do shell script "sleep " & sleep_before_going_to_line # wait half a second - eclipse is slow
tell application "System Events" to key code 37 using command down #send command L
tell application "System Events" to keystroke line_number
tell application "System Events" to keystroke return
end open location
If your eclipse isn’t located at “/Applications/eclipse/Eclipse.app”, modify
1
set path_to_eclipse to "the/correct/absolute/path/of/Eclipse.app"
Save as Application OpenInEclipse.app under /Applications
edit /Applications/OpenInEclipse.app/Contents/Info.plist and replace the last
</dict>
</plist>
with:
<key>CFBundleIdentifier</key>
<string>com.unpeelingthemagic.AppleScript.Eclipse</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>OpenInEclipse</string>
<key>CFBundleURLSchemes</key>
<array>
<string>openineclipse</string>
</array>
</dict>
</array>
</dict>
</plist>
<html><body>
<a href="openineclipse://open?url=file:///etc/hosts&line=3">open /etc/hosts file in eclipse and go to line 3</a>
</body></html>
Integrate with xdebug
add the following to php.ini in the xdebug section:
1
xdebug.file_link_format = "openineclipse://open?url=file://%f&line=%l"
1
$ sudo apachectl restart
Troubleshooting
In the AppleScript Editor uncomment:
1
display alert "DEBUG: file " & filename & " line " & line_number
Click on link again:
In the alert, are the filename and line_number parsed correctly? verify the href tag is correct or and that the code correctly parses the parameters
The alert displays the filename correctly but it doesn’t open:
Make sure path_to_eclipse is set to the correct location “/Applications/eclipse/Eclipse.app”
1
set path_to_eclipse to "the/correct/absolute/path/of/Eclipse.app"
Make sure eclipse is able to open a file from terminal, maybe your eclipse version is too old?
1
$ open -a /path/to/your/eclipse.app /etc/hosts
the file opens but it doesn’t go to the line number:
for system events to work with key code, you must “Enable access for assistive devices” in “System Preferences” under “Universal Access”
If you change the keyboard shortcut for go to line in eclipse, you’ll have to change the following line to send the correct key
1
tell application "System Events" to key code 37 using command down #send command L
finally, you can try to increase the sleep time before eclipse tries ‘go to line’ by modifying the following:
1
set sleep_before_going_to_line to "0.5" # in seconds
An alert does not display
LaunchServices is supposed to automatically register URL protocols of applications dragged to /Applications
You can see a list of all applications with registered url schemes as well as other information:
1
$ /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump > registeredapps.txt
`
under the bundle with the path: /Applications/OpenInEclipse.app you should find a claim id with the bindings openineclipse:
You can force OSX to re-register the url scheme of all applications in /Applications with the following command:
1
$ /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f -r /Applications
or you can use the system’s python to register just OpenInEclipse’s url scheme:
import LaunchServices
from Foundation import NSURL
appURL = NSURL.fileURLWithPath_("/Applications/OpenInEclipse.app")
status = LaunchServices.LSRegisterURL(appURL, True)