Trouble with a script for Powerpoint.

Hey everyone, need a bit of help here.

There is a great gentleman over at the Apple forums who has helped me with a script for Powerpoint Presentations. I am finding that many of my users are losing their entire presentation edits even though autosave is turned on. So I asked for some help and Camelot was very helpful.

However the Apple forums are offline, and my users are in the throes of making major presentations, and I want to roll this script out ASAP due to the fact that we have had issues with 10.4, and Powerpoint.

The script saves the presentation every 45 minutes (at this point, it can be changed) with a time and date stamp. The first version, kept tagging on the next time stamp so Camelot did a fix so that it would replace out the time stamp with the new one. Now we are getting an error that says:

Can’t make characters 1 thru offset of presName of “test-1.ppt” of application “Microsoft PowerPoint” into type Unicode text.

on idle
	-- run the save handler
	doSave()
	-- come back in 10 minutes and do it all again
	return 1 * minutes
end idle

on doSave()
	tell application "Microsoft PowerPoint"
		-- get the current document's path
		set savePath to path of presentation 1
		-- if it's not empty (i.e. the file has already been saved at least once)
		if savePath ≠ "" then
			-- get the current date in a format suitable for file names
			set datestring to my getDateString()
			-- work out where the new file should be saved
			set presName to (get name of presentation 1)
			set newFilePath to savePath & ":" & characters 1 through ((offset of "-" in presName) of presName) & "-" & datestring & ".ppt"
			-- and save it
			save presentation 1 in newFilePath
		end if
	end tell
end doSave

on getDateString()
	-- get the current date..
	set curDate to (get current date)
	-- ... and the time
	set theTime to time of curDate
	-- format a string in the form YYYYMMDDHHMM
	-- if you want some other format, define it here
	return year of curDate & (month of curDate as integer) & day of curDate & getHour(theTime) & getMinute(theTime) as text
end getDateString

on getHour(theTime)
	return theTime div hours
end getHour

on getMinute(theTime)
	return theTime mod hours div minutes
end getMinute

Thanks for helping!

Camelot, He’s a great guy. It would appear on my limited testing that Powerpoint is not liking the offset command. This worked for me.

on idle
	-- run the save handler
	doSave()
	-- come back in 10 minutes and do it all again
	return 1 * minutes
end idle

on doSave()
	tell application "Microsoft PowerPoint"
		-- get the current document's path
		set savePath to path of presentation 1
		-- if it's not empty (i.e. the file has already been saved at least once)
		if savePath ≠ "" then
			-- get the current date in a format suitable for file names
			set datestring to my getDateString()
			-- work out where the new file should be saved
			set presName to (get name of presentation 1)
			tell application "Finder" to set OS to offset of "-" in presName
			set newFilePath to savePath & ":" & characters 1 through (OS - 1) of presName & "-" & datestring & ".ppt"
			-- and save it
			save presentation 1 in newFilePath
		end if
	end tell
end doSave

on getDateString()
	-- get the current date..
	set curDate to (get current date)
	-- ... and the time
	set theTime to time of curDate
	-- format a string in the form YYYYMMDDHHMM
	-- if you want some other format, define it here
	return year of curDate & (month of curDate as integer) & day of curDate & getHour(theTime) & getMinute(theTime) as text
end getDateString

on getHour(theTime)
	return theTime div hours
end getHour

on getMinute(theTime)
	return theTime mod hours div minutes
end getMinute

Something to consider though… In the original incarnation filenames after a second save would end up with “–date”. Additionally the script would error if the filename didnt contain a “-” to begin with. I did a very quick fix for that which sorta fixed both. The first issue becomes revsolved but in the case of the second you come up with a filename like this ThePresentation.ppt-date.ppt

My workaround which properly accounts for both would be this (only the IF block presented to save space)

if savePath ≠ "" then
		-- get the current date in a format suitable for file names
		set datestring to my getDateString()
		-- work out where the new file should be saved
		set presName to (get name of presentation 1)
		tell application "Finder" to set OS to (offset of "-" in presName) - 1
		if OS is -1 then set OS to -5
		set newFilePath to savePath & ":" & characters 1 through OS of presName & "-" & datestring & ".ppt"
		-- and save it
		save presentation 1 in newFilePath
	end if

That did it…

I can at least have a couple of days to rest easy :wink:

There seems to be a bug in PowerPoint where autosave isn’t working. So you do 3 hours worth of work, Powerpoint crashes and guess what…

you get nothing…

Except some very very angry users…

I have explained to them about doing save as every so often… and you think they would listen to me after the first few times they lose their presentation.

But no… They continue to ignore my sound advise and get mad when they lose changes…

Since I am a complete noob… I am reading books on Applescript. I am thinking of trying to turn this thing into a sort of application that will allow the user to choose the save times, and some other not thought of functions.

Again…

Thanks for the help. You have save me some sanity, and my users…well… you saved them from themselves…

John

Glad to be of help John!

That would be a pretty neat little application btw that you mentioned… I actually wasn’t familiar with the PowerPoint bug you described, but thankfully we don’t really use that at my location. Just bewae the day your people start using “-” in their presentation name… that’s going to screw up the scripts naming convention a bit =)