Monday, May 20, 2019

#1 2019-05-11 12:11:16 pm

gtrnz
Member
Registered: 2019-03-15
Posts: 2

Getting numbers to remove a dynamic range of columns

Im trying to get AppleScript to sort the table and keep only the first 8 columns, the total number of columns often varies each use, as well as the column names.
This script gets it done but when there's less columns it throws errors as it runs out of columns to remove when the amount of columns is less than the repeat amount.

Is there a way to tell it to select column 9 to the last column and remove the selection?
Or any better way of handling this?

tell application "Numbers"
    tell document 1 to tell sheet 1 to tell table 1
        sort by column 1 direction ascending
       
        repeat 22 times
            remove column 9
        end repeat
    end tell
end tell

Last edited by gtrnz (2019-05-11 12:12:09 pm)

Offline

 

#2 2019-05-11 02:53:15 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 123

Re: Getting numbers to remove a dynamic range of columns

Applescript:


tell application "Numbers"
   activate
   tell document 1 to tell sheet 1 to tell table 1
       sort by column 1 direction ascending
       repeat 22 times
           try
               remove column 9
           on error
               exit repeat
           end try
       end repeat
   end tell
end tell


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Online

 

#3 2019-05-11 03:49:03 pm

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

Re: Getting numbers to remove a dynamic range of columns

Or:

Applescript:


tell application "Numbers"
   activate
   tell table 1 of sheet 1 of document 1
       set columnCount to (count columns)
       if (columnCount > 8) then remove (columns 9 thru columnCount)
       sort by column 1 direction ascending
   end tell
end tell


NG

Offline

 

#4 2019-05-12 06:35:34 am

gtrnz
Member
Registered: 2019-03-15
Posts: 2

Re: Getting numbers to remove a dynamic range of columns

Thanks for the help guys, solved it for me

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)