Monday, October 26, 2020

#1 2020-10-13 02:58:41 am

Amelie
Member
Registered: 2020-03-30
Posts: 13

Set the height of row I to 21

I have the following AppleScript:

Applescript:

tell application "Pages"
       set Rij to2
       set index of window DocumentNaam to 1
       tell (front document)
           set the Tabel to (the first table whose name is "XXXX")
           tell Tabel
               repeat with i from 1 to 3
                   make new row at (after row Rij)
                   set Rij to Rij + 1
                   set the height of row Rij to 21
               end repeat
           end tell
       end tell

I have two questions:

     1. If I search on the internet, I should use 'add row' in stead of 'make new row'. But add row doesn't work. Can anyone tell me why?

     2. If, the repeat loop is done the first time, he sets the row height to 21, as asked. But when I=2, he set the height to 21 BUT the height of the former row to 20. When I=3; he sets the new row to 21, the former last to 20 and the second last to 19.  What am I doing wrong?


Thank in advance!

Offline

 

#2 2020-10-13 04:27:00 am

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

Re: Set the height of row I to 21

Hi Amelie.

Before version 5.0, Pages was far more scriptable than it is now. It had 'add chart' and 'add table' commands, but as far as I know, it's never had an 'add row' command. Numbers still has 'add row above' and 'add row below' commands.

Unhelpfully, your script fragment works exactly as expected on my machine.  hmm  You could, though, make use of the specifier returned by the 'make' command to ensure that it's the new row whose height is being set.

Applescript:

tell application "Pages"
   set Rij to 2
   --set index of window DocumentNaam to 1
   tell (front document)
       set the Tabel to (the first table whose name is "XXXX")
       tell Tabel
           repeat with i from 1 to 3
               set height of (make new row at (after row Rij)) to 21
               set Rij to Rij + 1
           end repeat
       end tell
   end tell
end tell

Or perhaps something like this:

Applescript:

tell application "Pages"
   set Rij to 2
   --set index of window DocumentNaam to 1
   tell (front document)
       set the Tabel to (the first table whose name is "XXXX")
       tell Tabel
           set thisRow to row Rij
           repeat 3 times
               set thisRow to (make new row at after thisRow)
               set height of thisRow to 21
           end repeat
           set Rij to address of thisRow
       end tell
   end tell
end tell


NG

Offline

 

#3 2020-10-13 05:15:15 am

Amelie
Member
Registered: 2020-03-30
Posts: 13

Re: Set the height of row I to 21

Hi,

I have found what is causing my problem.
In pages there is the option of a table: "match rows to cell contents" (excuse me, if it is not correct translated, but I've a dutch version of pages). When this option is turned on, the script behaves correctly. But, when it is turned off, the script behaves as told in my former post.

Does somebody know what is causing the difference?

Last edited by Amelie (2020-10-13 06:49:04 am)

Offline

 

#4 2020-10-13 08:19:02 am

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

Re: Set the height of row I to 21

My understanding that you didn't identify the real problem.
I tested Pages 8.1 which is the last version usable on my machine with an open document embedding a table named "XYZ".
Below is the test script:

Applescript:

tell application "Pages"
   activate
   tell (document 1)
       iWork items --> {}
       tables --> {}
       set Tabel to (first iWork item whose name is "XYZ")
       --> error number -1719 from iWork item 1 of document 1 whose name = "XYZ"
   end tell
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 13 octobre 2020 16:17:21

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)