1

I have an idea for a class project which involves changing the desktop background image at different times. I saw these questions:

Can I change my Windows desktop wallpaper programmatically in Java/Groovy?

Programmatically change the desktop wallpaper periodically

Change desktop background of MAC sytem using Java native access

So I know it can be done on a specific operating system. Is it possible to set it for different operating systems without writing separate programs?

Community
  • 1
  • 1
bgardner
  • 45
  • 5
  • You can check the OS and call the proper method for changing the background image based on the OS. – nhgrif Nov 05 '13 at 00:38

1 Answers1

2

You can just use:

String os = System.getProperty("os.name");

to determine what OS the app is running on, and decide what to do from there. Like so:

if (os.startsWith("Windows")) {
    // includes all Windows versions
} else if (os.startsWith("Mac")) {
    // includes all Mac OS versions
} else {
    // all others
}

I suggest looking up all of the different values os.name can have to be able to handle as many as possible. You might want to use enums for these values instead of checking startsWith like I did. Here is a list of values you might want to consider (although not very up to date).

Daniel Larsson
  • 6,278
  • 5
  • 44
  • 82