如何在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/