Monday, July 22, 2019

#1 2019-07-12 01:53:49 am

Karstenj1
Member
Registered: 2019-07-11
Posts: 4

Keynote insert shape with text

Hello

I am new to applescript which may mean this is a simple question.

I am trying to copy and paste a text into a keynote slide at a certain location or position.

The following script will not work for some reason. The error messages are:

1) object text is not recognized. A : is expected after object. The properties of a shape do include object text though.

2) when I exclude the text part and run the script it won't recognize shape and asks for a definition of shape as a variable. This is despite the fact that shape is a defined word in the keynote library with its properties.

I can't find anything appropriate here nor more broadly.

Thanks in advance.

Here is the script:

tell application "Keynote"
    set PanelN to "test"
    set horizontalPosition to 587
    set verticalPosition to 488
    tell the slide
        set thisShape to ¬
            make new shape with properties ¬
                {position:{horizontalPosition, verticalPosition}, width:5, height:7, object text:PanelN, opacity:100}
    end tell
end tell

Offline

 

#2 2019-07-12 02:50:40 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3471

Re: Keynote insert shape with text

It seems that something is broken in Keynote support.

If we remove the part of the instruction defining the object text, the script compiles the wrong way.

Applescript:

tell application "Keynote"
   set PanelN to "test"
   set horizontalPosition to 587
   set verticalPosition to 488
   tell the slide
       set thisShape to make new shape with properties ¬
           {position:{horizontalPosition, verticalPosition}, width:5, height:7, opacity:100}
       
   end tell
end tell

shape is not treated as a Keynote object displayed in italic blue but as a variable displayed in green.

It seems that a bug report would be required.


I checked with the two other applications. In Pages and Numbers, shape is correctly compiled.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 12 juillet 2019  10:50:13

Last edited by Yvan Koenig (2019-07-12 03:09:22 am)

Offline

 

#3 2019-07-15 01:24:43 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4911

Re: Keynote insert shape with text

Hi both. I've just noticed this thread.

You need a proper specifier for the slide, which is in turn an element of a document. eg.:

Applescript:

tell application "Keynote"
   set PanelN to "test"
   set horizontalPosition to 587
   set verticalPosition to 488
   tell document 1 -- Added.
       tell slide 1 -- Changed. Adjust as required.
           set thisShape to ¬
               make new shape with properties ¬
                   {position:{horizontalPosition, verticalPosition}, width:5, height:7, object text:PanelN, opacity:100}
       end tell
   end tell
end tell

The shape created with the dimensions given above is very small, but the script works!


NG

Offline

 

#4 2019-07-16 10:51:21 am

Karstenj1
Member
Registered: 2019-07-11
Posts: 4

Re: Keynote insert shape with text

Thanks Nigel! And as you said, the box is tiny...

The hierarchy is great input. I now wonder if I am missing a hierarchical step when trying to further define properties such as:

background fill type:no fill
--(or background color:{250,250,250} ?)
font name:"Helvetica Neue"
alignment:left
text color:{0,0,0}
vertical alignment:center
font size:12

None of these works within shape. But they are properties of a cell, column or row. Obviously not part of Keynote.

Alternatively, I have pasted a pre-formatted text from Numbers into Keynote and find all properties above to be correct except for the position of the text box. So if I could only move the text box to a specific location inside the slide, that would help as well. Here is the script I tried, but it didn't work either:

tell application "Numbers" to activate --NUMBERS
delay 0.2
-- bring "System Events" to the front
tell application "System Events"
    delay 0.2
    key code 36 using option down
    keystroke "a" using command down
    keystroke "c" using command down
end tell

-- bring "Keynote" to the front
tell application "Keynote" to activate --KEYNOTE
delay 0.2
-- bring "System Events" to the front
set horizontalPosition to 587
set verticalPosition to 723
tell application "System Events"
    delay 0.2
    keystroke "v" using command down
end tell
tell application "Keynote"
    delay 0.2
    tell document 1
        tell slide 1
            move shape to slide 1 with properties {position:{horizontalPosition, verticalPosition}}
        end tell
    end tell
end tell

Offline

 

#5 2019-07-16 11:52:52 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4911

Re: Keynote insert shape with text

Karstenj1 wrote:

Alternatively, I have pasted a pre-formatted text from Numbers into Keynote and find all properties above to be correct except for the position of the text box. So if I could only move the text box to a specific location inside the slide, that would help as well.


Hi Karstenj1.

If you've successfully copied the text box into the slide, you should be able to change its position by setting the position to what you want:

Applescript:

tell application "Keynote"
    delay 0.2
    tell document 1
        tell slide 1
            set position of shape 1 to {horizontalPosition, verticalPosition}
        end tell
    end tell
end tell

The same with any other of its properties you want to change.

By the way, if you enclose your AppleScript code in MacScripter's [applescript] and [/applescript] tags when you post it, it'll appear formatted as in Yvan's and my posts, with a clickable link to open it in people's script editors. There's a button for these tags just above the text window on posting pages.

Last edited by Nigel Garvey (2019-07-16 03:48:24 pm)


NG

Offline

 

#6 2019-07-16 01:05:11 pm

Karstenj1
Member
Registered: 2019-07-11
Posts: 4

Re: Keynote insert shape with text

This didn't work. It is probably trying to move the slide as opposed to the shape or textbox.

Thanks for the link tipp.

Karsten

Offline

 

#7 2019-07-16 03:43:48 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4911

Re: Keynote insert shape with text

Karstenj1 wrote:

This didn't work. It is probably trying to move the slide as opposed to the shape or textbox.


You're right. Sorry. I was in a bit of hurry. I've now edited (and hopefully corrected!) the script above.


NG

Offline

 

#8 2019-07-18 10:48:49 am

Karstenj1
Member
Registered: 2019-07-11
Posts: 4

Re: Keynote insert shape with text

Thanks Nigel, appreciate your help very much! It is working now.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)