Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

zwerdlds

macrumors newbie
Original poster
Dec 22, 2008
6
0
I'm writing a program that sets the desktop background. I've looked around and found 'solutions' that are either insanely overly complicated or out of date.

Simply, given a URI to an image and an NSScreen id, how do I set the background?

Thanks in advance.
Dave
 

zwerdlds

macrumors newbie
Original poster
Dec 22, 2008
6
0
that would be the outdated solution. id like to avoid apple events if i can - they're just so ugly and I'd like to have a possibility of understanding what my own code does at some point in my finite existence.

any other ideas? anyone?
 

zwerdlds

macrumors newbie
Original poster
Dec 22, 2008
6
0
the other issue with the deskpictappdockmenu app is that it isnt capable of identifying the screen...
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
I just tested this with my laptop and external display by changing the desktop number, and it works. If you're targeting 10.5+ you could use Scripting Bridge to do it directly in Cocoa.

Code:
tell application "System Events"
	set picture of desktop 1 to POSIX file "~/Pictures/Photo Booth/Photo 1.jpg"
end tell
 

zwerdlds

macrumors newbie
Original poster
Dec 22, 2008
6
0
NSDictionary *props = [NSDictionary dictionaryWithObject:[NSURL URLWithString:pathToImage] forKey:mad:"path"];

syseventsAlias *desktopPictureFile = [[[sysEventsBridgeApp classForScriptingClass:mad:"file"] alloc] initWithProperties:props];

[[sysEventsBridgeApp aliases] addObject:desktopPictureFile];

NSLog([desktopPictureFile description]);

syseventsDesktop *thisDesktop = [sysEventsBridgeApp currentDesktop];

[thisDesktop setPicture:desktopPictureFile];


This doesn't work. The difficulty is in defining a file from a path. IE, you can retrieve a file from system events, but defining a file to look at is... well i'm not exactly sure how to do it, since the prop is readonly.

what i tried to do above is set it in a nsdictionary and pass it in as the initwithproperies argument, but it's failing.

how do we instantiate this?


Btw, here's the output when the above code is executed:
2008-12-24 19:24:14.553 MultiScape[4265:10b] Apple event returned an error. Event = 'core'\'crel'{ 'kocl':'file', 'insh':'insl'{ 'kobj':'obj '{ 'want':'alis', 'from':'null'(), 'form':'indx', 'seld':'abso'($206C6C61$) }, 'kpos':'end ' }, 'prdt':{ 'posx':'utxt'("/Users/zwerdlds/Pictures/MultiScape/1230175454.243843/16949552.tiff") } }
Error info = {
ErrorNumber = -10000;
}
 

zwerdlds

macrumors newbie
Original poster
Dec 22, 2008
6
0
Thread closed. Solution: setpicture accepts an nsurl as an argument.
 

HawaiiMacAddict

macrumors 6502a
Dec 28, 2006
904
0
On one of my Macs of course
Aloha Zwerdlds,

Have you tried Desk Decal? This does exactly what you described. I have it in my dock, and all I have to do is drag and drop the desired background file onto Desk Decal's dock icon to change my wallpaper. I understand the desire to learn how to do it yourself, but to say that all of the available 'solutions' are either insanely overly complicated or out of date is not quite accurate. Try Desk Decal and see what you think.

:apple:HawaiiMacAddict
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.