john renfrew Posted January 21, 2011 Posted January 21, 2011 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 }
dansmith65 Posted January 27, 2011 Posted January 27, 2011 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()
clemhoff Posted September 22, 2011 Posted September 22, 2011 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 }
Recommended Posts
This topic is 4880 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 accountSign in
Already have an account? Sign in here.
Sign In Now