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

Changing Desktop background to random iPhoto Event

I have a fairly robust script that resets the background to rotate every 30 seconds amongst jpgs in a random folder from a parent folder. It executes each morning to give me a new folder of images. I'd like to alter it to instead pull a random event from my iPhoto database. Anybody have any ideas on how to make that happen?

Here's the script I'm using for images in a folder:


global ResultList
set ResultList to {}
set picfile to some item of Check4Folders(alias "Macintosh HD:Users:vjdjr:Pictures:Mentor" as list)
tell application "Finder"
set TheFolderName to (picfile as alias) as text
end tell
tell application "System Events"
(*Rotating images from a random folder of images*)
tell current desktop
set picture rotation to 1 (*0=off, 1=interval, 2=login, 3=sleep*)
set random order to true
set pictures folder to file TheFolderName
set change interval to 30.0 -- seconds
end tell
end tell

on Check4Folders(flist)
-- This recursively adds every folder within the current folder to the Result list
tell application "Finder"
repeat with currentFolder in flist
set flist to folders of currentFolder
if (count of flist) > 0 then
set ResultList to ResultList & flist
my Check4Folders(flist)
end if
end repeat
end tell
return ResultList
end Check4Folders


Thanks,

Vince

Mac Book Pro, Mac OS X (10.6.6)

Posted on Feb 9, 2011 9:07 PM

Reply
15 replies

Feb 10, 2011 1:26 PM in response to vjdjr

I can't see how your script might be altered in order to do what you are asking for. However, using [GUI Scripting|http://www.macosxautomation.com/applescript/uiscripting/index.html], it's possible to write a script that could select an iPhoto event at random in the “Desktop & Screen Saver” window of the System Preferences. At least two drawbacks however: first, the “Desktop & Screen Saver” window will display for a few seconds each time the script is run; then, in order to use such a script, you will be required to enable the Accessibility Frameworks by clicking the checkbox labeled "Enable access for assistive devices" in the Universal Access System Preference pane.

Feb 10, 2011 9:51 PM in response to vjdjr

Hi

vjdjr wrote:
I'd like to alter it to instead pull a random event from my iPhoto database.
Vince


This script works for me.
I get the event names in the file "AlbumData.xml" (created by *iPhoto 09*).
Each folder in "Caches:Desktop:iPhoto Albums:" contains aliases.

set t_cache to (path to library folder from user domain as string) & "Caches:Desktop:iPhoto Albums:"
set t_name to Check4Folders(t_cache as alias)
set TheFolderName to (t_cache & t_name) as alias
tell application "System Events" to tell current desktop
set picture rotation to 1 (*0=off, 1=interval, 2=login, 3=sleep*)
set random order to true
set pictures folder to TheFolderName
set change interval to 30.0 -- seconds
end tell
on Check4Folders(f)
set eventNames to paragraphs of (do shell script "/usr/bin/grep -A3 'RollID' ~/Pictures/iPhoto\ Library/AlbumData.xml | /usr/bin/grep -v '<key>' | /usr/bin/sed 's/<\/integer>//;s/<\/string>//;s/<integer>//;s/<string>//' | /usr/bin/sed -n '2,${p;n;n;}' ")
tell application "Finder" to set folder_Names to (name of folders of f)
repeat 30 times
set t_name to some item of eventNames
if t_name is in folder_Names then return t_name -- return a iPhoto event name
end repeat
return some item of folder_Names -- else return a album or all photos
end Check4Folders

Feb 11, 2011 1:35 PM in response to vjdjr

Maybe you might want to try the following script. You may change the numbers in red in the first two lines of the script to fit your needs.

*set screenMode to item 1 of {"Fill Screen", "Fit to Screen", "Center"}*
*set frequency to item 1 of {"Every 5 seconds", "Every minute", "Every 5 minutes", "Every 15 minutes", "Every 30 minutes", "Every hour"}*
*tell application "System Preferences"*
* reveal anchor "DesktopPref" of pane id "com.apple.preference.desktopscreeneffect"*
* repeat until window "Desktop & Screen Saver" exists*
* delay 0.1*
* end repeat*
* tell application "System Events" to tell window "Desktop & Screen Saver" of process "System Preferences"*
* tell outline 1 of scroll area 1 of splitter group 1 of group 1 of tab group 1*
* repeat until (row 1 whose value of static text 1 of group 1 is "iPhoto") exists*
* delay 0.1*
* end repeat*
* set iPhotoRow to row 1 whose value of static text 1 of group 1 is "iPhoto"*
* if value of UI element 1 of group 1 of iPhotoRow is 0 then*
* click UI element 1 of group 1 of iPhotoRow* -- click disclosure triangle
* end if*
* set EventRow to row 1 whose value of static text 1 of group 1 is "Events"*
* if value of UI element 1 of group 1 of EventRow is 0 then*
* click UI element 1 of group 1 of EventRow* -- click disclosure triangle
* end if*
* set PhotoRow to row 1 whose value of static text 1 is "Photos"*
* set H to item 2 of (get size of row 1)* -- height of each row
* set Y0 to item 2 of (get position of row 1)* -- vertical position of the first row
* set Y1 to item 2 of (get position of EventRow)*
* set Y2 to item 2 of (get position of PhotoRow)*
* set theEvents to rows ((Y1 - Y0) div H + 2) through ((Y2 - Y0) div H)*
* select some item of theEvents*
* end tell*
* tell tab group 1*
* if value of checkbox 1 is 0 then click checkbox 1* -- checkbox “Change picture”
* if value of checkbox 2 is 0 then click checkbox 2* -- checkbox “Random order”
* if value of pop up button 1 is not frequency then*
* click pop up button 1*
* click menu item frequency of menu 1 of pop up button 1*
* end if*
* if value of pop up button 2 is not screenMode then*
* click pop up button 2*
* click menu item screenMode of menu 1 of pop up button 2* -- picture adjustment
* end if*
* end tell*
* end tell*
quit
*end tell*


Please let me know if the script doesn't work as expected.

Feb 13, 2011 12:14 PM in response to Pierre L.

Hi,

Pierre L. wrote:
Jacques, I tried to run your script, but didn't find any "Caches:Desktop:iPhoto Albums:" folder in my Library, although my iPhoto application seems to work properly. Is that folder a folder that must be specifically created for the script?


No, this is "*Preferences system*" (Mac OS X 10.5) that creates the folder when you select a
iPhoto event in the panel "*Desktop & Screen saver*", then you should click
on each event to create them all.
I don't know on *Mac OS X 10.6.*+

Feb 14, 2011 10:43 AM in response to Jacques Rioux

Thanks for your answer, Jacques.

I don't know on Mac OS X 10.6.+


Well, as far as I can say, it seems the folder you were talking about doesn't exist on Mac OS X 10.6.

I have clicked on each and every iPhoto event displayed in the “Desktop & Screen Saver” panel. But I am still unable to find any folder named “iPhoto Albums” in my Library, nor anywhere else actually.

Message was edited by: Pierre L.

Dec 30, 2012 7:24 AM in response to Pierre L.

I love what you have done Pierre and would like to ask if you help me tweek the script for my needs. I have 3 folders in my desktop list......Apple......iPhoto.....Folders. I have tweeked what you did to open the "Folders" folder. In there I have 5 sub folders....winter, spring, summer, fall, xmas.


Can you help me code it so it selects for example the Fall folder in the "Folders" folder. Thanks.




set screenMode to item 1 of {"Fill Screen", "Fit to Screen", "Center"}

set frequency to item 3 of {"Every 5 seconds", "Every minute", "Every 5 minutes", "Every 15 minutes", "Every 30 minutes", "Every hour"}


tell application "System Preferences"

reveal anchor "DesktopPref" of pane id "com.apple.preference.desktopscreeneffect"

repeat until window "Desktop & Screen Saver" exists

delay 0.1

end repeat

tell application "System Events" to tell window "Desktop & Screen Saver" of process "System Preferences"

tell outline 1 of scroll area 1 of splitter group 1 of group 1 of tab group 1

repeat until (row 1 whose value of static text 1 of group 1 is "Folders") exists

delay 0.1

end repeat

set FoldersRow to row 1 whose value of static text 1 of group 1 is "Folders"

if value of UI element 1 of group 1 of FoldersRow is 0 then


clickUI element 1 of group 1 of FoldersRow-- click disclosure triangle

end if

set EventRow to row 2 whose value of static text 1 of group 2 is "Fall"

if value of UI element 1 of group 1 of EventRow is 0 then


clickUI element 1 of group 1 of EventRow-- click disclosure triangle to open "Folders"

end if

tell application "Finder" to display dialog "stop 1" giving up after 1



--set folderRow4 to row 4 whose value of static text 1 is "Fall"


--set H to item 1 of (get size of row 4) -- height of each row


--set Y0 to item 1 of (get position of row 4) -- vertical position of the first row


--set Y1 to item 1 of (get position of EventRow)


--set Y2 to item 1 of (get position of folderRow2)


--set theEvents to rows ((Y1 - Y0) div H + 2) through ((Y2 - Y0) div H)


--select some item of theEvents

end tell


tell tab group 1

if value of checkbox 1 is 0 then clickcheckbox 1 -- checkbox “Change picture”

if value of checkbox 2 is 0 then click checkbox 2 -- checkbox “Random order”

if value of pop up button 1 is not frequency then


clickpop up button 1


clickmenu itemfrequency of menu 1 of pop up button 1 -- select every 5 min

end if


(*if value of pop up button 2 is not screenMode then

click pop up button 2

click menu item screenMode of menu 1 of pop up button 2 -- picture adjustment

end if*)

end tell

end tell


--quit

end tell

Dec 31, 2012 12:02 AM in response to FCPeditor

Try this (which I no longer can test under Mac OS X 10.6):


set screenMode to item 1 of {"Fill Screen", "Fit to Screen", "Center"}

set frequency to item 3 of {"Every 5 seconds", "Every minute", "Every 5 minutes", "Every 15 minutes", "Every 30 minutes", "Every hour"}


tell application "System Preferences"

-- activate

reveal anchor "DesktopPref" of pane id "com.apple.preference.desktopscreeneffect"

repeat until window "Desktop & Screen Saver" exists

delay 0.1

end repeat

tell application "System Events" to tell window "Desktop & Screen Saver" of process "System Preferences"

tell outline 1 of scroll area 1 of splitter group 1 of group 1 of tab group 1

repeat until (row 1 whose value of static text 1 of group 1 is "Folders") exists

delay 0.1

end repeat

set folderRow to row 1 whose value of static text 1 of group 1 is "Folders"

if value of UI element 1 of group 1 of folderRow is 0 then

clickUI element 1 of group 1 of folderRow-- click disclosure triangle

end if

repeat until (row 1 whose value of static text 1 is "Fall") exists

delay 0.1

end repeat

select (row 1 whose value of static text 1 is "Fall")

end tell

tell tab group 1

if value of checkbox 1 is 0 then clickcheckbox 1 -- checkbox “Change picture”

if value of checkbox 2 is 0 then clickcheckbox 2 -- checkbox “Random order”

if value of pop up button 1 is not frequency then

clickpop up button 1

clickmenu itemfrequency of menu 1 of pop up button 1

end if

end tell

end tell

quit

end tell

Dec 31, 2012 6:09 AM in response to Pierre L.

it works, thank you very very much. How did you learn to code for GUI purposes. I downloaded Prefab and played around awhile until I got this code to work to select the folder I wanted. Thanks again.



-- select THE SEASON FOLDER

tell application "System Events"

if UI elements enabled then

tell application process "System Preferences"

try

select row 10 of outline 1 of scroll area 1 of splitter group 1 of group 1 of tab group 1 of window "Desktop & Screen Saver"

end try

end tell

end if

end tell

Changing Desktop background to random iPhoto Event

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