Script: A Random Slideshow in Photos with Titles as Notifications, July 2019 version

by: 
Last modified: Aug 24, 2019 3:03 AM
2 2762 Last modified Aug 24, 2019 3:03 AM

Only a slideshow project allows us to add title slides or to adjust the timing for individual slides. But there are no sort options for slideshow projects. Albums allow us to sort the phots easily, but we cannot control the duration of individual slides. If we use a script to control the timing by "Pause" and "Resume", we have more options.

Here is an example script for controlling a slideshow using a script: The script will do the following:

  • Get the currently selected items in Photos and create a list of the selection
  • Shuffle the list of photos randomly
  • Start a slideshow.
  • For each slide it will pause for a specified amount of time and display the title of the slide.


The script has been tested in Photos 4.0 on Mojave. It runs well, when launched from the Script Editor, but sometimes will hang, when run from the scripts menu.

-- This script will play the currently selected items as a slideshow and shuffle the items for random results
-- The Moments name, the title, and the filename will be displayed in the notification center
-- To be able to see the notifications, enable "System Preferences > Notifications" for Script Editor.
-- Set the style to "Banners" and disable "Do not disturb" in the Notification center.
-- Run this script directly from Script Editor using the Run button and stop it using the stop button. 
-- Push the script editor window to the border of the display or ssign it to a different desktop than photos.
-- When I save the script as an application and run the application, the notifications do not show in the notification center

-- Before you run the script, select the photos on Photos that you want to use as the slideshow
-- If you do not want to shuffle the photos, set the variable "Shuffle" to false
-- The variable showslide_duration controls the duration, how long a slide is shown

-- test with small selections of photos, if you want to shuffle the slides.  The shuffling takes a long time for a large set of photos.




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 Shuffle to true -- set this to false, if you do not want to shuffel the photos randomly
set showslide_duration to 3 --- show each slide for three seconds

set thephotos to getCurrentSelection()

repeat 10 times
	
	tell application "Photos"
		set nitems to (count of thephotos)
		
		if Shuffle then -- shuffle the slide if Shuffle is true
			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
		end if -- Shuffle
		
		
		
		start slideshow using thephotos as list
		repeat with im in thephotos
			pause slideshow
			set nTitle to " "
			set ndesc to " "
			
			tell im
				try -- get the title of the photo
					set nTitle to its name as string
					if nTitle is equal to "missing value" then
						set nTitle to " "
					end if
				end try
				
				set nDate to its date as string -- get the date				
				set nFname to its filename as string --get the filename
				try
					set ndesc to its description as string -- get the description
					if ndesc is equal to "missing value" then
						set ndesc to " "
					end if
				end try
			end tell
			set theMoments to {nDate} -- default, only the date, if the moment cannot be retrieved			
			try
				set thisId to id of im
				set theMoments to the name of (moments whose id of media items contains thisId)
			end try
			
			
			display notification ndesc with title (nTitle & " " & nFname) subtitle (item 1 of theMoments)
			set the clipboard to (nFname & " " & nTitle & " " & (item 1 of theMoments))
			
			delay showslide_duration
			
			resume slideshow
			next slide
		end repeat
		stop slideshow
		
	end tell
end repeat

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