• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

open default OS file manager to a specific folder

 
Fon Drank
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to add an action to my java application that takes a user to a specific directory when they click on the toolbar icon. For users using Windows, this is easy since I can just call explorer.exe from the command line. However, I don't know the equivalent in Mac OS or Linux. Can anyone help with this? I think in mac, I can use /usr/bin/open?

if (System.getProperty("os.name").beginsWith("Windows"))
{
Runtime.getRuntime().exec("explorer.exe " + path);
} else if (System.getProperty("os.name").indexOf("Linux")!=-1)
{
// What goes here?
} else if (System.getProperty("os.name").beginsWith("Mac"))
Runtime.getRuntime().exec("usr/bin/open" + path); // is this right?
...
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code for the Mac seems to be right for OS X - aside from missing a space after the /usr/bin/open. I don't know if it would work for older systems, but that's probably not a small number of users anyway.

Another option is if you're using JDK 6, you can use java.awt.Desktop to open() the directory with simple platform-independent code. That's nice, but only works if you can reasonably expect your users to have JRE 6 installed. For some applications that may be a perfectly reasonable expectation, but for others, not.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The more save command for Windows platforms is the "start" command. That also not only works for folders, but also for all kinds of files.
 
Fon Drank
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is Java 6 officially released?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is Java 6 officially released?


Not for the Mac.
 
Fon Drank
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was a good idea, but I doubt it will work. I just tried it with the JDNC library, which is basically the same as java.awt.Desktop, and I got a error back "The given file is a directory".


Originally posted by Jim Yingst:
Your code for the Mac seems to be right for OS X - aside from missing a space after the /usr/bin/open. I don't know if it would work for older systems, but that's probably not a small number of users anyway.

Another option is if you're using JDK 6, you can use java.awt.Desktop to open() the directory with simple platform-independent code. That's nice, but only works if you can reasonably expect your users to have JRE 6 installed. For some applications that may be a perfectly reasonable expectation, but for others, not.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic