Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Apple script to change Desktop Picture

I've been slightly disappointed by the built in desktop picture changer in Mac OS X, as it won't look through sub folders, and I like to keep my pictures more organised than that.

I was wondering, can I script something with Applescript to this, ie pick a random picture from a list of folders, and change to this every 5 minutes.

Is there an applescript command to change the Desktop Picture, or is this idea a total non-starter.

iMac 24" Intel, Mac OS X (10.4.8)

Posted on Feb 6, 2007 12:57 PM

Reply
Question marked as Best reply

Posted on Feb 6, 2007 3:22 PM

Hi Rob,

Here's a fairly robust example of a random desktop picture changer that uses an idle handler. You save idle handlers as stay open application. As is, it changes the desktop picture every 5 seconds.

property default_folder : path to "pdoc" -- current user's Pictures folder
property extension_list : {"jpg", "tiff", "pdf"}
property idle_minutes : 0
property idle_seconds : 5
global main_folder
--
on run
-- initialize variables, if any
end run
--
on reopen
set main_folder to choose folder with prompt "Choose folder with jpegs:"
end reopen
--
on idle
repeat
try
set this_jpg to some item of GetFiles(main_folder)
exit repeat
on error -- no jpgs in current main_folder
set main_folder to default_folder
end try
end repeat
tell application "Finder"
set desktop picture to this_jpg
end tell
return idle_minutes * minutes + idle_seconds -- return in n seconds
end idle
--
on GetFiles(this_folder)
set utid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {return}
tell application "Finder"
set file_listing to ¬
(every file of this_folder whose name extension is in extension_list) as string
end tell
set AppleScript's text item delimiters to utid
if file_listing is "" then
set file_list to {}
else
set file_list to paragraphs of file_listing
end if
tell application "Finder" to set sub_folders to every folder of this_folder
repeat with sub_folder in sub_folders
set file_list to file_list & GetFiles(sub_folder)
end repeat
return file_list
end GetFiles

Edited: I first started with just jpegs. Hence, the comments and prompts refer to jpegs. Then I added more extension types. You can modify the few properties that were included.

gl,
2 replies
Question marked as Best reply

Feb 6, 2007 3:22 PM in response to Rob S UK

Hi Rob,

Here's a fairly robust example of a random desktop picture changer that uses an idle handler. You save idle handlers as stay open application. As is, it changes the desktop picture every 5 seconds.

property default_folder : path to "pdoc" -- current user's Pictures folder
property extension_list : {"jpg", "tiff", "pdf"}
property idle_minutes : 0
property idle_seconds : 5
global main_folder
--
on run
-- initialize variables, if any
end run
--
on reopen
set main_folder to choose folder with prompt "Choose folder with jpegs:"
end reopen
--
on idle
repeat
try
set this_jpg to some item of GetFiles(main_folder)
exit repeat
on error -- no jpgs in current main_folder
set main_folder to default_folder
end try
end repeat
tell application "Finder"
set desktop picture to this_jpg
end tell
return idle_minutes * minutes + idle_seconds -- return in n seconds
end idle
--
on GetFiles(this_folder)
set utid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {return}
tell application "Finder"
set file_listing to ¬
(every file of this_folder whose name extension is in extension_list) as string
end tell
set AppleScript's text item delimiters to utid
if file_listing is "" then
set file_list to {}
else
set file_list to paragraphs of file_listing
end if
tell application "Finder" to set sub_folders to every folder of this_folder
repeat with sub_folder in sub_folders
set file_list to file_list & GetFiles(sub_folder)
end repeat
return file_list
end GetFiles

Edited: I first started with just jpegs. Hence, the comments and prompts refer to jpegs. Then I added more extension types. You can modify the few properties that were included.

gl,

Feb 7, 2007 10:15 AM in response to kel

Thanks Kel, that script seems just what I am after.

But, I can't seem to get it to work. I've saved it as a stay open application from the Apple Script editor, but when I run the script I just get a black and white spinning wheel.

From reading the script, I think it's supposed to prompt me for a folder, but that doesn't seem to happen.

Do you have an ideas where I'm going wrong.

Apple script to change Desktop Picture

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.