Jump to content

Path to desktop


 Share

This topic is 4156 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Had the need to find users desktop path so it could point back to a local version of a dashboard/ launch file if they were not using the hosted version, so that I don't have to try and fill the Manage External Files dialogue with the paths to each users individual desktops. That way I can then use my SM script to open a file in its default app...

This seems to work on all the machines I can find, but if anyone has improvements or finds it breaks then please chip in...

// DeskFolder()

// 2011/01/20 JR

// v1

// returns path to desktop



import javax.swing.filechooser.*



sep = System.getProperty("file.separator")

os = System.getProperty("os.name").toLowerCase().substring(0,3)

fsv = FileSystemView.getFileSystemView()

if (os == 'mac') {

	return fsv.getHomeDirectory().toString() + sep + 'Desktop' + sep

} else {

	return fsv.getHomeDirectory().toString() + sep

}

Link to comment
Share on other sites

I just tested this on Windows Vista and it worked for me.

The only improvement I can think of is to not include all classes from javax.swing.filechooser, since you are only using one, and only using it once. This could be done two ways...

change

import javax.swing.filechooser.*

to

import javax.swing.filechooser.FileSystemView

- or -




change

fsv = FileSystemView.getFileSystemView()

to

fsv = javax.swing.filechooser.FileSystemView.getFileSystemView()

Link to comment
Share on other sites

  • 7 months later...

Hi John,

... or just with System Properties

sep = System.getProperty("file.separator")

home = System.getProperty("user.dir") + sep

//  or System.getProperty("user.home") + sep

 

if ( System.getProperty("os.name").toLowerCase().substring(0,3) == 'mac') {

	return home + 'Desktop' + sep

} else {

	return home

}

Link to comment
Share on other sites

This topic is 4156 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.