Launch NetBeans when opening files in the MacOS X Finder
I recently switched from Open Komodo to NetBeans 7. What drove me absolutely nuts was the fact that I couldn’t drag and drop files onto the NetBeans application to have them open. Further complicating the issue, NetBeans does not use a standard file browser dialog so you cannot drag and drop onto that either.
Here is my work around. It allows you to drag and drop a single file, or group of files and have them open in NetBeans. I created an application with AppleScript that takes the dropped files and passes them to a shell command that opens netbeans. To use this you must first have NetBeans already launched. I keep this application sitting in my Dock right next the NetBeans icon.
You may need to edit the path to NetBeans if you are using a different version or location
The AppleScript
-- This AppleScript created by John Kramlich of http://www.johnkramlich.com -- Modify it in anyway you see fit. return -- not needed, but shows that the script stops here when "run" on open of finderObjects -- "open" handler triggered by drag'n'drop launches repeat with i in (finderObjects) -- in case multiple objects dropped on applet set mypath to posix_path(i) do shell script "/Applications/NetBeans/NetBeans\\ 7.0.app/Contents/MacOS/netbeans --open " & mypath end repeat tell application "NetBeans 7.0" activate end tell end open on posix_path(mac_path) set mac_path to (mac_path as text) set root to (offset of ":" in mac_path) set rootdisk to (characters 1 thru (root - 1) of mac_path) tell application "Finder" if (disk (rootdisk as string) is the startup disk) then set unixpath to "/" & (characters (root + 1) thru end of mac_path) else set unixpath to "/Volumes:" & mac_path end if end tell set chars to every character of unixpath repeat with i from 2 to length of chars if item i of chars as text is equal to "/" then set item i of chars to ":" else if item i of chars as text is equal to ":" then set item i of chars to "/" else if item i of chars as text is equal to "'" then set item i of chars to "\\'" else if item i of chars as text is equal to "\"" then set item i of chars to "\\" & "\"" else if item i of chars as text is equal to "*" then set item i of chars to "\\*" else if item i of chars as text is equal to "?" then set item i of chars to "\\?" else if item i of chars as text is equal to " " then set item i of chars to "\\ " else if item i of chars as text is equal to "\\" then set item i of chars to "\\\\" end if end repeat return every item of chars as string end posix_path
