Currently Being Moderated

Script: Shuffle Photos for an Instant Slideshow in Random Order

Tested in Photos 1.5, OS X 10.11.5, El Capitan.

 

You can either pass the photos to be shuffled in a top-level album or by selecting them in Photos. Launch Photos.

Then launch this script from Script Editor.

This Apple Script will shuffle a list of selected  photos in Photos and present them as an instant slideshow in a random order:

 

set ReadFromAlbum to false

 

on getCurrentSelection()

  tell application "Photos"

  set imageSel to {}

  try

  set imageSel to (get selection)

  on error errTexttwo number errNumtwo

  display dialog "Cannot get the selection: " & errNumtwo & return & errTexttwo

  end try

  return imageSel

  end tell

end getCurrentSelection

 

on getPhotosInAnAlbum()

  set PhotoDropBoxName to "PhotoDropBox" -- the name of an album at the top level of the library

  tell application "Photos"

  if exists container PhotoDropBoxName then

  set myContainer to container PhotoDropBoxName

 

  --display dialog "TopLevel variable set"

  else

  display dialog "Album 'PhotoDropBox' doesn't exist. Please create an album called 'PhotoDropBox' and try again - Exiting" buttons ¬

  "OK" with icon caution default button "OK"

  return

  end if

  set myCount to count of media items in myContainer

 

  if (myCount = 0) then

  display dialog "The PhotoDropBox album is empty. Please add some photos." as text

  return

  else

  display dialog "About to process " & myCount & " item(s) in PhotoDropBox album" as text

  return every media item of myContainer

  end if

 

  end tell

 

end getPhotosInAnAlbum

 

if (ReadFromAlbum) then

  set thephotos to getPhotosInAnAlbum() -- get a list of photos from the album "PhotoDropBox"

else

  set thephotos to getCurrentSelection()

end if

 

set nitems to (count of thephotos)

if (nitems > 1) then

  repeat nitems times --shuffle the photos in the list

  set split to random number (nitems - 2) + 1

 

  if (split < 1) then

  set split to 1

  end if

 

  if split is 1 then

  set head to {}

  set tail to items 2 thru nitems of thephotos

  end if

 

  if split is nitems then

  set head to items 1 thru (nitems - 1) of thephotos

  set tail to {}

  end if

 

  if (split > 1) and (split < nitems) then

  set head to items 1 thru (split - 1) of thephotos as list

  set tail to items (split + 1) thru nitems of thephotos as list

  end if

  set thephotos to head & tail & (item split of thephotos as list)

  end repeat

end if

 

 

tell application "Photos"

 

  start slideshow using thephotos as list

end tell

 

--return thephotos

 

 

I tried, but it does not seem to be possible to create a shuffled album. When I add a photo to an album from a script, the photos  will always be sorted by date.  The scripting support in Photos is still limited. It is also not possible to create a slideshow project from Photos. We can only control existing slideshows.

Replies

Delete User Tip

Are you sure you want to delete this user tip?