Thursday, June 4, 2020

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

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

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: 4391

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: 5205

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: 7

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: 5205

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: 7

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: 5205

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: 7

Re: Keynote insert shape with text

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

Offline

 

#9 2019-09-25 01:50:11 pm

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

Re: Keynote insert shape with text

Hi Nigel

Your script isn't working for some reason. I had it working on a shape, but on an image, it is not:

Applescript:


tell application "Keynote"
   tell document 1
       tell slide 4
           set position of image 1 to {94, 122}
       end tell
   end tell
end tell

I wonder if you know why.

Cheers
Karsten

Offline

 

#10 2019-09-25 04:40:12 pm

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

Re: Keynote insert shape with text

Hi Karstenj1.

It seems to be a bug in Keynote, or in its AppleScript implementation. On my machine, only the vertical coordinate is heeded when setting an image position. The horizontal coordinate's totally ignored!  hmm

The only way I can see round it at the moment is a mixture of Keynote and GUI scripting:

Applescript:

set thePosition to {94, 122} -- Adjust as required.

tell application "Keynote"
   activate
   tell document 1
       tell slide 4
           -- While this only moves the image vertically, it does also select it.
           set position of image 1 to thePosition
       end tell
   end tell
end tell

tell application "System Events"
   tell application process "Keynote"
       set frontmost to true
       tell window 1
           -- If the "Format" button in the toolbar's not selected, click it and wait for the "Arrange" button in the "Format" pane to appear.
           -- The details in the pane will be for the image just selected above.
           -- You may need to translate "Arrange" into your own language.
           set formatButton to radio button 1 of radio group 1 of toolbar 1
           if (formatButton's value is 0) then
               click formatButton
               repeat until radio button "Arrange" of radio group 1 exists
                   delay 0.2
               end repeat
           end if
           -- Click the "Arrange" button.
           click radio button 3 of radio group 1
           -- Fill in the X coordinate text field.
           tell text field "X" of scroll area 1
               set focused to true
               set value to (beginning of thePosition) as text
           end tell
       end tell
   end tell
   -- Apply the setting.
   keystroke return
end tell


NG

Offline

 

#11 2019-09-26 01:42:09 am

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

Re: Keynote insert shape with text

Thanks Nigel - works well enough for me.

Offline

 

#12 2019-10-02 04:13:17 am

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

Re: Keynote insert shape with text

Hi Karstenj1.

Keynote 9.2 was released a day or two ago. The image positioning bug now seems to have been fixed.


NG

Offline

 

#13 2019-10-02 07:50:10 am

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

Re: Keynote insert shape with text

Nigel Garvey wrote:

Hi Karstenj1.

Keynote 9.2 was released a day or two ago. The image positioning bug now seems to have been fixed.




Alas, this new version requires 10.14 or higher !

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 2 octobre 2019  15:49:56

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)