I try to copy a shortcut file into the desktop. I have made a lot of research about this.

On Linux, I check if XDG_DESKTOP_DIR is set and non empty. If not, I check if $HOME/.config/user-dirs.dirs exists; if so, I call ". $HOME/.config/user-dirs.dirs". Then, I can use System.getenv("XDG_DESKTOP_DIR"). Using directly XDG_DESKTOP_DIR is enough on GNOME but not on KDE (.config/user-dirs.dirs is useful in this case).

On Mac, I'm not sure $HOME/Desktop works for non English users. Does someone have a better idea? I don't really know AppleScript...

What are you trying to do which requires you to find the desktop folder without asking the user where it is?

I'm trying to create a shortcut on the desktop. This feature is quite broken in Java Web Start. Mine is almost currently ready for Linux, Windows will require a bit more work and I have no idea of how to implement it on Mac.

Just to throw it out there, there are other ways to get the desktop on Windows via Batch to WShell or the registry here.

I personally would use the WShell method as I believe registry access is more likely to be locked down.

If all your checks fail you can also just fall back onto checking if '~/desktop' folder exists as if it does then it's probably going to be their desktop (although yes, this is far from certain but the fact the folder exists does make it more likely).

Just to throw it out there, there are other ways to get the desktop on Windows via Batch to WShell or the registry here.

I personally would use the WShell method as I believe registry access is more likely to be locked down.

If all your checks fail you can also just fall back onto checking if '~/desktop' folder exists as if it does then it's probably going to be their desktop (although yes, this is far from certain but the fact the folder exists does make it more likely).

%USERPROFILE% is not present on very old Windows (95, 98). '~/desktop' folder exists only on English desktops, I don't know on which versions of Windows WShell is available. Maybe I should find an heuristic method if the registry method fails.

Why not have a couple of default checks, such as '~/Desktop/' or the equivalent on Windows. If that doesn't exist, then just ask the user where they'd like to put the shortcut (and you could write it somewhere in case they install a second game of yours and you could just look it up).

This way, you get the common case really easily but you have a valid fallback for the weird OS installs, old versions or non-English OS's (which you won't be able to get correct all of the time anyway).

Why not have a couple of default checks, such as '~/Desktop/' or the equivalent on Windows. If that doesn't exist, then just ask the user where they'd like to put the shortcut (and you could write it somewhere in case they install a second game of yours and you could just look it up).

This way, you get the common case really easily but you have a valid fallback for the weird OS installs, old versions or non-English OS's (which you won't be able to get correct all of the time anyway).

Actually the registry method rarely fails. JL235's suggestion would be an excellent fallback, I would like to use such a source code but in Java:

1 2 3 4 5

useWin32::OLE;

my $wsh = newWin32::OLE'WScript.Shell';

my $desktop_path = $wsh->SpecialFolders('Desktop');

I don't want to prompt the user.

I could use this:

1

WScript.Echo(WScript.SpecialFolders("Desktop"));

If I do this:

1

wscript//NoLogo //B

does a Windows user see a logo or a command display when I use WScript?

I have found no way of getting the desktop directory on Mac OS X. Is there a Mac user here?

On Mac OS X, whatever the locale, it seems to be:Mac OS X/Users/<username>/Library/DesktopI can get this with System.getProperty("user.home")+"/Desktop".On Mac OS 9, it seems to be:Macintosh HD:Users:<User Name>:Desktop Folder

Using the registry on Windows might cause some localization problems and the use of "Shell Folders" registry key is deprecated since Windows Vista then I will use WShell.

%USERPROFILE% is not present on very old Windows (95, 98). '~/desktop' folder exists only on English desktops

If your making a game then will it even run on a machine still running Windows 95 or 98; will they even have a recent version of Java installed? I'd presume it's there but fall back onto asking or doing nothing if it's not.

What is the likely hood of a pre-Vista Windows user (English or non-English) having a folder called 'Desktop' in their home directory which isn't their desktop? I'd bet it's extremely low. If it's there and you used it then I'd imagine it's the right place 99.9% of the time (although again I'd only do this as a fall back option).

If your making a game then will it even run on a machine still running Windows 95 or 98; will they even have a recent version of Java installed? I'd presume it's there but fall back onto asking or doing nothing if it's not.

%USERPROFILE% is not localized, it cannot be used but you're right, I'm even not sure it is possible to install Java 1.6 on Windows 95.

What is the likely hood of a pre-Vista Windows user (English or non-English) having a folder called 'Desktop' in their home directory which isn't their desktop? I'd bet it's extremely low. If it's there and you used it then I'd imagine it's the right place 99.9% of the time (although again I'd only do this as a fall back option).

Lots of people still use Windows XP and I have a lot of French users (as I'm French). I suggest using the following algorithm:- use WScript.SpecialFolders("Desktop") as it is the most reliable and not deprecated way of getting this piece of information since Windows 98if it does not work - use the registry method and replace the environment variables by their values (as I did for Linux) if it does not work - try to use System.getProperty("user.home")+"\Desktop" as Riven says this directory always exists on Vista and 7

Can I use Runtime.getRuntime().exec() to execute the WShell command lines? What displays WScript.Echo(WScript.SpecialFolders("Desktop")); on your machine?

Edit.: Java 1.6 cannot be installed on Windows 98 but still on Windows 2000.Edit.2: I will use a simple bash script on Mac as it seems very complicated to create an Alias

The Mac's desktop is always located at '~/Desktop' for English versions, I'm not sure if it's different for non-English but Mac has a pretty rigid folder convention. The is always located in /Users/<username/Desktop (you had an extra Library folder there, which is incorrect). Reading here (http://osx.tribe.net/thread/ea74316d-e1f6-4de7-a518-0836864bc7fb) it appears that within the Terminal, localized installs still use paths named Desktop and just display the translated version with the GUI folder environment.

The Mac's desktop is always located at '~/Desktop' for English versions, I'm not sure if it's different for non-English but Mac has a pretty rigid folder convention. The is always located in /Users/<username/Desktop (you had an extra Library folder there, which is incorrect). Reading here (http://osx.tribe.net/thread/ea74316d-e1f6-4de7-a518-0836864bc7fb) it appears that within the Terminal, localized installs still use paths named Desktop and just display the translated version with the GUI folder environment.

It is not different for French users

Creating an alias (equivalent of a shortcut file on Mac) is so complicated, I'm going to use a simple bash script.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org