You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Script: Shuffle Photos for an Instant Slideshow in Random Order 2018

by: 
Last modified: Dec 29, 2018 10:19 AM
6 10473 Last modified Dec 29, 2018 10:19 AM

Photos can play slideshows, but does not have the option to shuffle the photos randomly, like iPhoto and Aperture could.

Here is a simple Apple Script to take the currently selected photos and then run them as a slideshow. It is very basic. The Scripting dictionary for Photos does neither allow to select the theme for the slideshow nor the music.

Just select the photos in Photos, then run the script from the Script Editor or the Scripts menu. This version of the script has been tested in macOS 10.14.2 Mojave


----- copy from here and paste into Script Editor

-- this script will play the currently selected items as a slideshow and shuffle the items for random results

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

set thephotos to getCurrentSelection()

repeat 10 times
	set showslide_duration to 4 --- four seconds
	
	tell application "Photos"
		set nitems to (count of thephotos)
		repeat 3 times --shuffle three times for more randomness
			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
		end repeat
		
		
		
		
		start slideshow using thephotos as list
		--	return thephotos
		
		
		
	end tell
end repeat


---- copy until here



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.

This user tip replaces the previous version: Script: Shuffle Photos for an Instant Sli… - Apple Community


A compiled version of this script can be downloaded from Old Toad's Tutorial site:

http://www.oldtoadstutorials.net/No.P01.html


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