setting desktop picture from open panel

Ok, so I’m trying to make a browse button that will set the desktop picture to the chosen file. After choosing the picture the image loaded correctly in the image view but the desktop picture did not change.

this is what i have

on clicked theObject
	if name of theObject is "choose1" then
		set browsechoice to "1"
		set can choose files of open panel to true
		set can choose directories of open panel to false
		display open panel attached to window of theObject
	else if name of theObject is "choose2" then
		set browsechoice to "2"
		set can choose files of open panel to true
		set can choose directories of open panel to false
		display open panel attached to window of theObject
	else if name of theObject is "choose3" then
		set browsechoice to "3"
		set can choose files of open panel to true
		set can choose directories of open panel to false
		display open panel attached to window of theObject
	else if the name of theObject is "gotosite" then
		tell application "System Events"
			open location target_URL
		end tell
	end if
end clicked
on panel ended theObject with result withResult
	if withResult is 1 then
		set imagePath to path name of open panel
		
		if browsechoice = "1" then
			set image of image view "image1" of box "box1" of window "main" to load image imagePath
			tell application "Finder" to set desktop picture to imagePath --this is what isnt working
		else if browsechoice = "2" then
			set image of image view "image2" of box "box2" of window "main" to load image imagePath
		else if browsechoice = "3" then
			set image of image view "image3" of box "box3" of window "main" to load image imagePath
		end if
	end if
end panel ended

Hi Hendo,

the result of path name of panel ended is a POSIX path.
The Finder wants a string, file specifier or alias to set the desktop picture


.
tell application "Finder" to set desktop picture to POSIX file imagePath as alias
.

PS: Don’t forget to release the images from memory after using it :wink:

ah! worked great! Thanks!