Applescript code for inset a rectangle box in Keynote document
Hi Friends,
I would like to insert a new object (it may be rectangle, text frame, or oval shape) in to the slide.
For that I write the below applescript code, but it is not working, can you please guide me to get solution?
tell application "Keynote"
-- Check if there is a Keynote document open
if (count of documents) > 0 then
set theDoc to the front document
-- Loop through each slide in the document
repeat with slideIndex from 1 to count of slides of theDoc
set currentSlide to slide slideIndex of theDoc
-- Insert a rectangle shape (correct approach)
try
-- Create a rectangle
set newRectangle to make new rectangle at currentSlide
-- Set position and size separately
set position of newRectangle to {50, 50} -- Position of the rectangle
set size of newRectangle to {200, 100} -- Size of the rectangle
log "Rectangle inserted successfully on slide " & slideIndex
on error errMsg
log "Error inserting rectangle on slide " & slideIndex & ": " & errMsg
end try
-- Insert a text box (for example)
try
set newTextBox to make new text item at currentSlide with properties {position:{300, 300}, size:{200, 50}, object text:"Hello, Keynote!"}
set font size of newTextBox to 24
set font name of newTextBox to "Helvetica"
log "Text box inserted successfully on slide " & slideIndex
on error errMsg
log "Error inserting text box on slide " & slideIndex & ": " & errMsg
end try
-- Insert a circle (oval shape)
try
-- Create an oval
set newCircle to make new oval at currentSlide
-- Set position and size of the oval (circle)
set position of newCircle to {600, 50}
set size of newCircle to {100, 100}
log "Circle (oval) inserted successfully on slide " & slideIndex
on error errMsg
log "Error inserting circle on slide " & slideIndex & ": " & errMsg
end try
end repeat
-- Notify when done
display dialog "Objects insertion completed."
else
-- If no Keynote document is open
display dialog "No Keynote document is open." buttons {"OK"} default button "OK"
end if
end tell