You are not logged in.
Hi all,
my name is Phil and I'm rather new to doing AppleScript. I'm currently facing the following problem:
We want to create personalized powerpoint presentations for client send out. AppleScript should first ask the user about the name and company name of the client. Apple script shall call up the Master Presentation and should look for the placeholders "%company%" and "%name%" and should replace them with the user input. I've found quite a few pieces of code for word and excel but can't figure out on how to get it running on ppt.
I guess its not that hard but I couldn't find anything suitable within the last hours...
Thx a million for helping.
Best,
Phil
So far I have compiled the following:
set persname to the text returned of (display dialog "Name?" default answer "")
set company to the text returned of (display dialog "Company?" default answer "")
set filepath to POSIX path of "Path...:Company Presentation MASTER.pptx"
try
set command to "open " & quoted form of filepath
do shell script command
end try
Offline
Try this:
Applescript:
property theName : "%name%" as text
property theCompany : "%company%" as text
set theFile to choose file with prompt "Select Master PPT File"
set persname to the text returned of (display dialog "Enter Person Name?" with title "Master PPT Query" default answer "")
set company to the text returned of (display dialog "Enter Company Name?" with title "Master PPT Query" default answer "")
tell application "Microsoft PowerPoint" to open theFile
pptTextReplace(theCompany, company)
pptTextReplace(theName, persname)
on pptTextReplace(findText, replaceText)
tell application "Microsoft PowerPoint"
activate
repeat with slideNumber from 1 to count of slides of active presentation
tell slide slideNumber of active presentation
repeat with shapeNumber from 1 to count of shapes
set shapeText to content of text range of text frame of shape shapeNumber
if shapeText = findText then
set content of text range of text frame of shape shapeNumber to replaceText
end if
end repeat
end tell
end repeat
end tell
end pptTextReplace
Offline
Hi haolesurferdude,
This is brilliant! Thank you very much for that. It works almost as expected.
Remaining problem is that the search terms are mainly within a context (sentences) of a text box.
In this case, the code wouldn't execute as
[code] if shapeText = findText then[/code]
would return false for those textboxes.
Is there any way of digging one level deeper within the text box?
Best,
Phil
Last edited by phil_zrh (2017-06-30 02:03:02 am)
Offline
Try this:
Applescript:
property theName : "%name%" as text
property theCompany : "%company%" as text
set theFile to choose file with prompt "Select Master PPT File"
set persname to the text returned of (display dialog "Enter Person Name?" with title "Master PPT Query" default answer "")
set company to the text returned of (display dialog "Enter Company Name?" with title "Master PPT Query" default answer "")
tell application "Microsoft PowerPoint" to open theFile
pptFindNReplace(theCompany, company)
pptFindNReplace(theName, persname)
on pptFindNReplace(findText, replaceText)
tell application "Microsoft PowerPoint"
activate
repeat with slideNumber from 1 to count of slides of active presentation
tell slide slideNumber of active presentation
repeat with shapeNumber from 1 to count of shapes
set shapeText to content of text range of text frame of shape shapeNumber
set newText to my replaceText(shapeText, findText, replaceText)
if newText ≠shapeText then
set content of text range of text frame of shape shapeNumber to newText
end if
end repeat
end tell
end repeat
end tell
end pptFindNReplace
on replaceText(theText as text, findString as text, replaceString as text)
(* Takes a text string and replaces the findString with the replaceString. Can be just 1 character in either or both findString and replaceString. *)
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, findString}
set textItems to text items of theText
set AppleScript's text item delimiters to replaceString
set theResult to textItems as text
set AppleScript's text item delimiters to oTIDs
return theResult
end replaceText
Offline
This looks super useful! I ran it against some of the templates I typically use, trying it out as a more global PPT text find/replace, and ran into an issue. Sometimes "shapeText" comes up empty and causes the script to halt.
I added a test for this missing value condition in your subroutine to resolve this:
Applescript:
on pptFindNReplace(findText, replaceText)
tell application "Microsoft PowerPoint"
activate
repeat with slideNumber from 1 to count of slides of active presentation
tell slide slideNumber of active presentation
repeat with shapeNumber from 1 to count of shapes
set shapeText to content of text range of text frame of shape shapeNumber
if shapeText is not missing value then
set newText to my replaceText(shapeText, findText, replaceText)
if newText ≠shapeText then
set content of text range of text frame of shape shapeNumber to newText
end if
end if
end repeat
end tell
end repeat
end tell
end pptFindNReplace
Offline
Good move!
Offline
Guys you're literally killing me! Can't tell you how you helped me out.
Will try asap to implement it and let you know!
Offline