objective-c - 在 Objective-C 中更改桌面图片

标签 objective-c cocoa unix terminal

如何在cocoa/objective-c中更改桌面图片?我尝试过使用默认值,但出现了很多错误。

NSArray *args=[NSArray arrayWithObjects:@"write",@"com.apple.desktop", @"Background", @"'{default = {ImageFilePath = \"~/desktop.jpg\";};}'", nil];

NSTask *deskTask=[[NSTask alloc] init];

[deskTask setArguments: args];

[deskTask setLaunchPath:@"/usr/bin/defaults"];
[deskTask launch];
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"com.apple.desktop" object:@"BackgroundChanged"];

该命令在终端中成功运行。我不需要任何人告诉我确切要做什么,但我想要一些见解。

编辑:我的操作系统是 10.4.11

最佳答案

我认为规范的方法是将脚本与系统事件结合使用。 Applescript 版本类似于:

tell application "System Events"
    tell current desktop
        set picture to (whatever)
    end tell
end tell

您可以使用Scripting Bridge从 Objective-C 来做。

关于objective-c - 在 Objective-C 中更改桌面图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3533618/

相关文章:

iphone - 运行模拟器时出错 : duplicate symbol for architecture i386

objective-c - 将 Carbon 代码移植到 Cocoa 的策略

macos - 在基于nstable的 View 中获取选定的行和列

linux - 将最后四行移动到文本文件中的第二行

iphone - cocoa touch : NSDateComponents crashes on releasing a fresh instance

macos - NSTextField - 按下各个按键时的通知

objective-c - #import "Project-Swift.h"文件不刷新

linux - 关于 solaris 中的 grep

c++ - Unix C++ 简单服务器问题 : sending data back to browser

iphone - pushViewController 不工作