applescript numbers - rearrange / move columns

Hi,


I just started to use some applescript to do recurring tasks - and have some problem with the right way to use it. (Mac, Numbers 10.0)


I have a table with addresses in each row.

Now I have first name, last name, email, phone, country, city, street, zip company in each column.

But I want columns in a different order.

In the end it should be

company, first name, last name, street, city, country, phone, email

with a mouse you just pick the column and pull it to the new location to insert it.



I tried to use applescript to get it done.

I found the move command,


as first step and tried to move column "J" ("ZIP") to before "G" ("CITY")


So I tried unsuccessfully :


tell application "Numbers"

move column "J" of table 1 of sheet 1 of document 1 to before column "G"

end tell


error: column "G" cannot be read


I cannot get it to work and when searching for answers I find relatively complicated ways to move columns.


what is the easiest way to do it ?


thanks.



Mac mini 2018 or later

Posted on May 10, 2020 7:20 PM

Reply
4 replies

May 11, 2020 6:59 AM in response to bert240

Don't think there is an easy way to do that by script. Sometimes doing things manually is much more efficient.


The only way via script that I can get to work here is to do "gui-scripting", something like this, to switch the positions of column B and C, with an empty column D.


tell application "Numbers"
	tell active sheet of front document
		tell table 1
			set selection range to column "B"
			activate
			tell application "System Events" to keystroke "c" using command down
			set selection range to column "D"
			tell application "System Events" to keystroke "v" using command down
			delay 0.5
			delete column "B"
		end tell
	end tell
end tell



SG



May 12, 2020 10:07 PM in response to bert240

Hi Bert,


"two questions: what is the delay good for ?"


It gives the system time to complete the previous task ('paste all this stuff into column D') before starting the next one ( Delete column B).


" how to deselect a range at the end ?"


When the script is finished, click wherever your next task is to be done to select that location (and deselect the previously selected range).



one question: how did your postˆ"Thanks SG…the end?" solve your issue?

The Solved button marks the post as having solved the issue, and brings it to the top of the discussion, where it is more likely to be seen by someone arriving later with a similar or the same question.


Regards,

Barry

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

applescript numbers - rearrange / move columns

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.