Adrian Nier Code

Back to overview

Set desktop picture

Last modification: Friday, July 31, 2009 10:13 pm

Sets the desktop picture.

Required parameters
_imageFilePath (string)
HFS style path to the image file or a name for a file in the /Library/Desktop Pictures/Solid Colors/ directory (e.g. Solid Gray Dark).

Function Calls

-- Set the desktop picture to solid white
setDesktopPicture("Solid White")

-- Set the desktop picture to Classic Aqua Blue
setDesktopPicture((path to library folder from local domain as string) & "Desktop Pictures:Classic Aqua Blue.jpg")

Implementation

on setDesktopPicture(_imageFilePath)
   
   -- Check wether the image file exists
   tell application "System Events"
      if (exists file _imageFilePath) is false then
         set _originalPath to _imageFilePath
         
         -- Find out wether a name for a file out of the
         -- Solid Color directory has been specified
         set _imageFilePath to (path to library folder from local domain as string) & "Desktop Pictures:Solid Colors:" & _imageFilePath
         if (exists file _imageFilePath) is false then
            
            -- Maybe no suffix was specified.   
            set _imageFilePath to _imageFilePath & ".png"
            if (exists file _imageFilePath) is false then
               
               -- The file doesn't exist
               error "No file exists at path \"" & _originalPath & "\""
            end if
         end if
      end if
   end tell
   
   -- Set the desktop picture
   tell application "System Events"
      set picture of desktops to alias _imageFilePath
   end tell
end setDesktopPicture