January 21, 201114 yr 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 }
January 27, 201114 yr 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()
September 22, 201114 yr 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 }
Create an account or sign in to comment