Re: [HELP] How to change Desktop background pic in OSX from Cocoa-Java?
Re: [HELP] How to change Desktop background pic in OSX from Cocoa-Java?
- Subject: Re: [HELP] How to change Desktop background pic in OSX from Cocoa-Java?
- From: David Remahl <email@hidden>
- Date: Sun, 1 Jul 2001 14:49:59 +0200
BTW, some code like this would do the same work 'defaults write...'
would but in Cocoa code. I wrote it in Obj-C, because I'm not that into
Java, but I hope you can decipher the syntax...
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
//standard cocoa stuff
NSDictionary* finderPrefs = nil; // a dictionary to hold finder
preferences while we work on them
//get finder prefs from NSUserDefaults
finderPrefs = [[NSUserDefaults standardUserDefaults]
persistentDomainForName:@"com.apple.finder"];
//extract the "DesktopViewOptions" sub-dictionary and set the value of
the key locating the desktop to the desired path
[[finderPrefs objectForKey:@"DesktopViewOptions"]
setObject:@"file://localhost/Library/Desktop Pictures/Solid Aqua
Blue.tiff" forKey:@"BackgroundPictureURL"];
//put the modified settings back where they came from
[[NSUserDefaults standardUserDefaults]
setPersistentDomain:finderPrefs forName:@"com.apple.finder"];
//write the stuff to disk
[[NSUserDefaults standardUserDefaults] synchronize];
[pool release];
return 0;
}
The problem of letting finder know you changed the setting remains
however...
/ david
Further searching on the web revealed that a "Defaults Write.." could be
executed from the command-line altering the Finder's DesktopViewOptions
(as
you've shown below). This achieves the end-result but may well break in
the
future. I was hoping to be able to do this from within a higher-level
Framework (AppKit, Foundation). Remotely "Apple-Scripting" the Finder
may be
a cleaner solution but I don't know of any way to do this from
Java-Cocoa
and I don't know of a way to "view" the Finder's (or any app's)
AppleScript
dictionary.
Mark
-----Original Message-----
From: David Remahl [mailto:email@hidden]
Sent: Sunday, 1 July 2001 9:32 PM
To: Mark Orchard (BigPond Cable)
Cc: email@hidden; email@hidden
Subject: Re: [HELP] How to change Desktop background pic in OSX from
Cocoa-Java?
On Sunday, July 1, 2001, at 01:13 PM, Mark Orchard ((BigPond Cable))
wrote:
Hi,
Apologies if this question has been asked before or if I'm missing
something
obvious.
I'm beginning to explore the world of Cocoa using Java and I'd like to
find
a way to change the Desktop background picture in MacOS X.
I didn't see anything in the AppKit or Foundation docs that could help.
Is
this a Unix or lower-level System thing?
Any help or pointer to the right direction or list would be greatly
appreciated.
Uhm, actually it is a Finder thing...Finder is responsible for the
desktop and it does what it sees fits with the background...Finder
stores its preferences for the desktop in this structure in its .plist
preferences file:
DesktopViewOptions = {
ArrangeBy = grid;
BackgroundFlags = 0;
BackgroundPictureURL =
"file://localhost/Users/chmod007/Pictures/Familjebilder/Digitalkamera Tach
a/
MVC-020S.JPG";
BackgroundType = PctB;
IconSize = 32;
};
But I dont think that that is anything you should go in and modify since
the format may change in the future...A change would also require a
restart of finder...I doubt it, but maybe finder supports changing the
background using applescript...
/ david
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev