• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

open default OS file manager to a specific folder

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
...
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is Java 6 officially released?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic