Test Text Frames in PowerPoint using AppleScript

Hi.

I have PowerPoint slides with some text boxes and images. I want the script to take the top one (the is a title) and the one just below it, that is the main text, and change its properties. Just that, no change to the rest of the slide.

My script is like this, but:

  1. It only works if I “select all” first.
  2. It is using the selection X,Y in the “IF”, to it is formating them all the same.

What I need is to go to the slide, without selecting anything (if possible), and cycle to all text frames to check if they are the ones I need, and format them.

The two frames are not necessarily Shape 1 and Shape 2 on the slide.

tell application "Microsoft PowerPoint"
	activate
	--tell front document
	set allShapes to shape range of selection of active window
	set shapeCount to (count shapes of allShapes)
	
	set shapeList to {}
	set slideNumber to 31
	
	repeat with i from 1 to shapeCount
		tell shape i of allShapes
			set positionX to left position
			set positionY to top
			set nameE to name
			
			
			if positionX < 100 then
				
				
				if positionY < 2 then
					set properties to {top:{-2}, left position:{35}, width:{350}, height:{59.8}}
					tell font of text range of text frame of allShapes
						set font size to 24
						set font color to ({0, 0, 0} as RGB color)
					end tell
					tell paragraph format of text range of text frame of allShapes
						set space before to 0
						set space after to 4
					end tell
					
					set name to "Main Title"
				else
					set properties to {top:{77}, left position:{35}, width:{360}, height:{280}}
					tell font of text range of text frame of allShapes
						set font size to 18
					end tell
					tell paragraph format of text range of text frame of allShapes
						set space before to 0
						set space after to 4
					end tell
					set name to "Main Text"
				end if
			end if
		end tell
	end repeat
	
	
end tell

My “logic” is to test if the frame is in the left portion of the screen (X < 100 will work for both), and if it is the top frame (Y < 2), format with font 24 (and etc.). and if it’s X < 100 and Y > 2, it’s enough to know it’s the other frame and format if with font 18 (and etc.).

Any idea? I got stuck and it should be simple. :slight_smile:

Thank you,
Luiz

This should do what you want.
It uses the current slide.
Be aware that if there is more than 2 text frames in the slide, any of them whose top position is more than 2 will be formatted as “Main text”.

tell application "Microsoft PowerPoint"
	activate
	
	set currentSlide to (slide of view of active window)
	set theShapes to shapes of currentSlide
	
	repeat with aShape in theShapes
		
		tell aShape
			set positionX to left position
			set positionY to top
			
			if positionX < 100 then
				
				if positionY < 2 then
					set properties to {top:{-2}, left position:{35}, width:{350}, height:{59.8}}
					tell font of text range of text frame of it
						set font size to 24
						--set font color to {0, 0, 0} -- rvb black color
						set font color theme index to first text theme color -- 1st text color from palette (should be black)
					end tell
					tell paragraph format of text range of text frame of it
						set space before to 0
						set space after to 4
					end tell
					
					--set content of text range of text frame of it to "Main Title" -- for tests
					set name to "Main Title"
				else
					set properties to {top:{77}, left position:{35}, width:{360}, height:{280}}
					tell font of text range of text frame of it
						set font size to 18
					end tell
					tell paragraph format of text range of text frame of it
						set space before to 0
						set space after to 40
					end tell
					
					--set content of text range of text frame of it to "Main Text" -- for tests
					set name to "Main Text"
				end if
			end if
		end tell
	end repeat
	
end tell

Thanks a lot, @ionah. It worked very well. It is a very smart and simple solution. Thank you!

Hi, @ionah. I made some “improvements” to the script to make it do a lot of other things and it’s working very well (thank you again). I just want to make another question if you don’t mind: is there a way to change the shape z-order? I see it’s a read only property, but maybe there is a way.

Thank you,
Luiz

This is the syntax:

z order theShape z order position send shape behind text

The possible values are:

bring shape forward
bring shape in front of text
bring shape to front
send shape backward
send shape behind text
send shape to back

Thank you. It is giving me an error when compiling (it highlights “command”) but I make some testes this afternoon.

Thank you again!

Sorry, it’s a bad copy/paste.
I’ve amended my precedent post.

Thanks A LOT! I was getting crazy trying to make it work. Hahaha.