"Hi everybody! Hi dr. Nick!"
I'm really not a fan of JFileChooser - It's as anti-mac-looking as possible. So I messed around with FileDialog. I gave up on that because it's ancient compared to Swing and seems to have been abandoned by the Coffee Gods. I shoveled my way even deeper down by trying to figure out how to use a Finder/Explorer window instead of the given Java options (FileDialog, JFileChooser). I found this neat thread at JavaRanch:
Open a folder in finder in Java (Mac OS forum at JavaRanch)
"Houston, we have a problem", though. I'm to dimwitted to understand the sample code given by "Andrew Monkhouse". I thank him sincerely for lending internet a hand, but apparently, he doesn't explain his solution. I'm talking about this part:
public class ColinMcTaggart { private static final String[] prefix = { "osascript", "-e", "tell application \"Finder\"", "-e", "activate", "-e", "<openCmdGoesHere>", "-e", "end tell" }; public static void main(String[] args) throws Exception { prefix[6] = buildFolderCommand(System.getProperty("user.dir")); Runtime.getRuntime().exec(prefix).waitFor(); } private static String buildFolderCommand(String folderPath) { StringBuilder openCommand = new StringBuilder("open "); String[] pathParts = folderPath.split("/"); for (int i = pathParts.length - 1; i > 0; i--) { openCommand.append("folder \"").append(pathParts[i]).append("\" of "); } return openCommand.append("startup disk").toString(); } }
I ran the code and it worked perfectly. I just don't understand it. The first part was some osascript that opened the finder. The rest doesn't make sense to me. Could you decode this piece of information to me and future researchers?
Also, is it possible to interact with the Finder window? Can you set filters, get selected files, etc? It's probably possible with osascript. What do you think?
If it's not possible, I'd rather create my very own file dialog, which I think is the best choice of all above anyways, hardest but most awarding. Got any tips on that?
Thanks!