Change desktop background of MAC sytem using Java native access

时间秒杀一切 提交于 2019-12-31 03:44:28

问题


I have got a code snippet to change system desktop using JNA, it is worked fine for me.

What change i need to make this code for working on Mac Os.

Help is highly appreciated.

Thanks, Shihab.


回答1:


Looks like you need to Map the NSWorkspace class to JNA. Define an interface that extends Library class in JNA. Then map the setDesktopImageURL:forScreen:options:error: method ot JNA.

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/Reference/Reference.html




回答2:


Here's how you can do it without JNA.

public void setWallpaper(File file)
throws Exception {
    String as[] = {
            "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);
}

Credits

https://stackoverflow.com/a/5007344/1401250

https://sourceforge.net/p/jawc-wallpaperc/code/HEAD/tree/trunk/Jawc/src/it/jwallpaper/platform/impl/MacPlatform.java#l38



来源:https://stackoverflow.com/questions/6199907/change-desktop-background-of-mac-sytem-using-java-native-access

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!