I have had some trouble with a small program I am working on. All it does is change the desktop picture to something else. But I cant do something like this:
static File aFile = new file.getClass().getResource(name)
Instead I use this:
static File aFile = new File("/Library/Application Support/Adobe/Adobe PCD/cache/SOURCE CODES/troller/Troller/src/1.jpg");
I would like the image for the program to put the desktop, available in the jar file, but I can only say where the image is with a full file path. (A think its called Absolute Path) So how would I make the file find the image wherever the compiled jar would be. (assuming that the image is in the jar with the program.) Might be something i'm doing wrong with making everything static.Here is the entire program:
import java.io.File;
public class Main {
static File aFile = new File("/Library/Application Support/Adobe/Adobe PCD/cache/SOURCE CODES/troller/Troller/src/1.jpg");
static Main troll = new Main();
public static void main(String[] args) {
try {
setWallpaper(aFile);
} catch (Exception e) {
System.out.println("Execption lel");
e.printStackTrace();
}
}
public static void setWallpaper(File file) throws Exception
{
String as[] = new String[]
{
"osascript",
"-e", "tell application \"Finder\"",
"-e", "set desktop picture to POSIX file \"" + file.getAbsolutePath() + "\"",
"-e", "end tell"
};
Runtime runtime = Runtime.getRuntime();
Process process;
process = runtime.exec(as);
System.out.println("Test");
}
}
Thanks in advance.