Here’s a script that creates an image grid presentation using the photos from a chosen iPhoto album. The script incorporates both image creation and image replacement techniques as well as a creative design to provide an interesting kiosk effect. (Click Movie to Play)
As you can see in the video, this script incorporates the use of a Keynote theme that contains slide masters for a grid of image placeholders and for a full-slide square image placeholder.
Image Grid Kiosk
Open in Script Editor
01 property thisThemeName : "Image Grid Kiosk"
02 property gridSlideMasterName : "Photo - Grid 28"
03 property photoSlideMasterName : "Photo"
04 property squarePhotoSlideMasterName : "Photo - Square"
05
06 property defaultAutomaticTransistion : true
07 property defaultImageDisplayTime : 3
08
09 tell application "Keynote"
10 activate
11
12 if playing is true then tell the front document to stop
13
14 try
15
16 set the templateNames to the name of every theme
17 if thisThemeName is not in the templateNames then error number 1000
18
19
20 set albumNames to my iPhotoalbumNames ()
21 if albumNames is false then error number 1001
22 set chosenAlbum to ¬
23 (choose from list albumNames with prompt ¬
24 "Pick the album containing images to import:")
25 if chosenAlbum is false then error number -128
26
27
28 tell application "iPhoto"
29
30
31 set the imagePaths to ¬
32 the preview path of every photo of album (chosenAlbum as string )
33 set albumImageCount to the count of the imagePaths
34 if albumImageCount is 0 then error number 1002
35 end tell
36
37 display dialog "Enter the title for the presentation:" default answer ""
38 set the presentationTitle to the text returned of the result
39
40 set thisDocument to ¬
41 make new document with properties {document theme :theme thisThemeName }
42
43 tell thisDocument
44
45 tell the current slide
46 set base slide to master slide "Title - Center" of thisDocument
47 set the object text of the default title item to the presentationTitle
48
49 set the transition properties to ¬
50 {transition effect :dissolve ¬
51 , transition duration :2 ¬
52 , transition Delay :3 ¬
53 , automatic transition :defaultAutomaticTransistion }
54 end tell
55
56
57 set gridSlide to make new slide with properties {base slide :master slide gridSlideMasterName }
58 tell gridSlide
59
60 set the transition properties to ¬
61 {transition effect :magic move ¬
62 , transition duration :2 ¬
63 , transition Delay :0 ¬
64 , automatic transition :defaultAutomaticTransistion }
65
66 set the gridCount to the count of images
67 set theseImagePaths to items 1 thru gridCount of the imagePaths
68 repeat with i from 1 to the gridCount
69 set thisImageFile to (item i of theseImagePaths ) as POSIX file
70 set the file name of image i to thisImageFile
71 end repeat
72 end tell
73 delay 1
74
75
76 repeat with i from 1 to the count of theseImagePaths
77 set thisImageFile to (item i of theseImagePaths ) as POSIX file
78 my addInboundSquarePhotoSlide (thisImageFile )
79 my addPhotoSlide (thisImageFile )
80 my addOutboundSquarePhotoSlide (thisImageFile )
81 delay 1
82 duplicate slide 2 to after last slide
83 delay 1
84 end repeat
85
86
87 tell gridSlide
88 set the transition properties to {transition Delay :2}
89 end tell
90
91
92 set auto play to true
93 set auto loop to true
94 end tell
95
96
97 start thisDocument from first slide of thisDocument
98
99 on error errorMessage number errorNumber
100 if errorNumber is 1000 then
101 display alert "MISSING RESOURCE" message "This script requires the installation of a Keynote theme titled “" & thisThemeName & ".”" & return & return & "The template can be downloaded from: iworkautomation.com" as critical buttons {"Download", "Stop"} default button 2
102 if the button returned of the result is "Download" then
103 open location "http://iworkautomation.com/keynote/examples-grid-kiosk.html"
104 end if
105 error number -128
106 else if errorNumber is 1001 then
107 set errorNumber to "iPhoto Issue"
108 set errorMessage to "There was a problem getting a list of albums from iPhoto."
109 else if errorNumber is 1002 then
110 set errorNumber to "iPhoto Issue"
111 set errorMessage to "The chosen album contains no photos."
112 else if errorNumber is 1003 then
113 set errorNumber to "iPhoto Issue"
114 set errorMessage to "There are more image placeholders than album images."
115 end if
116 if errorNumber is not -128 then
117 display alert (errorNumber as string ) message errorMessage
118 end if
119 end try
120 end tell
121
122 on iPhotoalbumNames ()
123 try
124
125 tell application "iPhoto"
126 launch
127 return (the name of every album )
128 end tell
129 on error
130 return false
131 end try
132 end iPhotoalbumNames
133
134 on addInboundSquarePhotoSlide (thisImageFile )
135 tell application "Keynote"
136 tell the front document
137 set thisSlide to ¬
138 make new slide with properties ¬
139 {base slide :master slide squarePhotoSlideMasterName }
140 tell thisSlide
141 set the file name of the first image to thisImageFile
142 set the transition properties to ¬
143 {transition effect :dissolve ¬
144 , transition duration :0.5 ¬
145 , transition Delay :0 ¬
146 , automatic transition :defaultAutomaticTransistion }
147 end tell
148 end tell
149 end tell
150 end addInboundSquarePhotoSlide
151
152 on addOutboundSquarePhotoSlide (thisImageFile )
153 tell application "Keynote"
154 tell the front document
155 set thisSlide to ¬
156 make new slide with properties ¬
157 {base slide :master slide squarePhotoSlideMasterName }
158 tell thisSlide
159 set the file name of the first image to thisImageFile
160 set the transition properties to ¬
161 {transition effect :magic move ¬
162 , transition duration :1.5 ¬
163 , transition Delay :0 ¬
164 , automatic transition :defaultAutomaticTransistion }
165 end tell
166 end tell
167 end tell
168 end addOutboundSquarePhotoSlide
169
170 on addPhotoSlide (thisImageFile )
171 tell application "Keynote"
172 tell the front document
173 set documentWidth to its width
174 set documentHeight to its height
175 set thisSlide to make new slide with properties {base slide :master slide "Blank"}
176 tell thisSlide
177 set thisImage to make new image with properties {file :thisImageFile }
178 tell thisImage
179 set its height to documentHeight
180 set its position to {(documentWidth - (its width )) div 2, 0}
181 end tell
182 set the transition properties to ¬
183 {transition effect :dissolve , transition duration :0.5 ¬
184 , transition Delay :defaultImageDisplayTime ¬
185 , automatic transition :defaultAutomaticTransistion }
186 end tell
187 end tell
188 end tell
189 end addPhotoSlide
190
191 on duplicateSlideToEnd (thisSlide )
192 tell application "Keynote"
193 tell the front document
194 duplicate thisSlide to after last slide
195 end tell
196 end tell
197 end duplicateSlideToEnd