Create Circles using AppleScript in Pages document.

I'm trying to create a circle (red line, no fill) in a pages document using AppleScript, but so far I only manage to get a black rectangle. I tried properties like 'shape type:"Oval"' and 'auto shape type:autoshape circle' but none of that would compile/work. Here is my code so far:


tell application "Pages"
	activate
	set theDoc to front document
	
	tell theDoc
		set thePage to page 1
		
		tell thePage
			set theCircle to make new shape
		end tell
		
		tell theCircle
			set position to {100, 200}
		end tell

	end tell
end tell


I'm using Pages version 14.4 (7043.0.93) and script editor version 2.11 (231) with AppleScript 2.8 on macOS 15.2 (24C101)

MacBook Pro 16″, macOS 15.2

Posted on Jul 9, 2025 10:22 AM

Reply
6 replies

Jul 10, 2025 07:13 AM in response to TechTobi

An SVG deposited into Pages has selection grips and those in its corners when dragged, allow one to resize that SVG without distortion. Try any other grip and it will distort.


Some SVGs that I have dragged and dropped into Pages have been recognized by Pages as Shapes that I could add to its Shapes library as My Shapes, while these hand-coded circles are treated as Images and not candidates for the Shapes Library.


I recommend that you select File menu > Open Dictionary… in the Script Editor, then scroll down to Pages. Those are the scripting properties for how you can interact with Pages using AppleScript. And yes, Apple has significantly dumbed down these properties from what they were in the old Pages '09 application.

Jul 9, 2025 11:27 AM in response to TechTobi

The Pages scripting dictionary does not allow you to specify what type of shape or its color to insert into a Pages document. You need to become clever to override that limitation.


Cleverness is a scalable vector graphics (SVG).


I have just created a simplistic red SVG circle in a text file on my Desktop named circle.svg containing just this text:

<svg height="100" width="100" xmlns="http://www.w3.org/2000/svg">
  <circle r="45" cx="50" http://www.w3.org/2000/svg">


Since Pages v14.4 can handle inserted SVG graphics, I can do the following in AppleScript:

use scripting additions

property USER : short user name of (system info)
property redCircle : "/Users/" & USER & "/Desktop/circle.svg"

tell application "Pages"
	activate
	
	set theDoc to the front document
	set thePage to first page of theDoc
	tell thePage
		set theCircle to (make new image with properties {file:redCircle, position:{100, 200}})
	end tell
end tell
return



More on SVG here, and here

Jul 9, 2025 12:13 PM in response to VikingOSX

Errata:


The filled red circle SVG file:

<svg height="100" width="100" xmlns="http://www.w3.org/2000/svg">
  <circle r="45" cx="50" chttp://www.w3.org/2000/svg" \>
</svg>


The red-stroked circle SVG file:

<svg height="100" width="100" xmlns="http://www.w3.org/2000/svg" version="1.1">
   <circle r="45" cx="50" cy="50" stroke="red" stroke-width="2" fill="none" />
</svg>


use scripting additions

property USER : short user name of (system info)
property redCircle : "/Users/" & USER & "/Desktop/circle_stroke.svg"

tell application "Pages"
	activate
	
	set theDoc to the front document
	set thePage to first page of theDoc
	tell thePage
		set theCircle to (make new image with properties {file:redCircle, position:{100, 200}})
	end tell
end tell
return





Jul 9, 2025 02:07 PM in response to VikingOSX

Thanks, but that doesn't solve the problem either, as the circle gets distorted in case it needs to be resized manually later on.


It's just frustrating that there is the possibility to create a "shape" object, but in reality, it is just a black rectangle that can't be controlled - perhaps it would be better to refractor that as "make new blackBox" ;-)

Jul 10, 2025 02:43 AM in response to VikingOSX

Update: Instead of this I am now trying to have a template red circle shape in the document that gets duplicated:


-- Select the shape ...		
set selection to originalShape
		
-- ... and use UI scripting with Cmd+C and Cmd+V to duplicate the shape
-- (using "duplicate" within Apple Script does not work, error -1717
-- which is why this requires shortcuts via system events)
tell application "System Events"
	tell process "Pages"
		keystroke "c" using command down
		delay 0.9
		keystroke "v" using command down
	end tell
end tell


This nearly works, only problem now is to figure out how to move the copy to the correct page.


I also tried to copy the properties of the template shape and make a new shape with these properties:


set theProperties to properties of originalShape
set newShape to make new shape at page 2 with properties theProperties


Interestingly enough, this causes Pages to crash ...

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Create Circles using AppleScript in Pages document.

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