使用Java本机访问更改MAC系统的桌面背景 [英] Change desktop background of MAC sytem using Java native access

查看:163
本文介绍了使用Java本机访问更改MAC系统的桌面背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码片段,可以使用 JNA ,它对我来说很好。

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

我需要做什么改变才能使用Mac Os上的代码。

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

非常感谢帮助。

谢谢,
Shihab。

Thanks, Shihab.

推荐答案

以下是没有JNA的方法。

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);
}

积分

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

这篇关于使用Java本机访问更改MAC系统的桌面背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆