Apple Script - Copy the second row of a table in numbers and paste it into the bottom line of a numbers table in another document

Hi,


Hope you're well.


Just a quick question regarding some apple script terminology.


I've been trying to write an apple script which will copy the lowest line on the table "Company Info" (photos below) and paste it on the the lowest line of a table in another Numbers file.


I think I've managed to copy the whole "Company Info" table, but I only want to copy the lowest line (the one containing the numbers). I'd then like to paste it into "Table 1" which is in a numbers filed titled "Paste Here."


Is there a way to do this?


Thank you in advance.

MacBook Air 13", 10.14

Posted on Feb 1, 2019 8:19 AM

Reply
Question marked as Top-ranking reply

Posted on Feb 2, 2019 6:46 AM

copy the lowest line on the table "Company Info" (photos below) and paste it 
on the the lowest line of a table in another Numbers file


Another way to do that would be the script below. This assumes there are at least as many columns in the receiving table as in the source table. If not one might want some error trapping.


SG


-- replace names with actual names in your documents
set srcDocNam to "MyDocName1.numbers"
set srcShtNam to "Sheet 1"
set srcTblNam to "Table 1"
set tgtDocNam to "MyDocName2.numbers"
set tgtShtNam to "Sheet 1"
set tgtTblNam to "Table 1"

tell application "Numbers"
	tell document srcDocNam's sheet srcShtNam's table srcTblNam
		set vv to last row's cells's value -- places last row's values in AppleScript list
	end tell
	tell document tgtDocNam's sheet tgtShtNam's table tgtTblNam
		repeat with c from 1 to column count
			set last row's cell c's value to vv's item c
		end repeat
	end tell
end tell


Similar questions

7 replies
Question marked as Top-ranking reply

Feb 2, 2019 6:46 AM in response to Apple_Script

copy the lowest line on the table "Company Info" (photos below) and paste it 
on the the lowest line of a table in another Numbers file


Another way to do that would be the script below. This assumes there are at least as many columns in the receiving table as in the source table. If not one might want some error trapping.


SG


-- replace names with actual names in your documents
set srcDocNam to "MyDocName1.numbers"
set srcShtNam to "Sheet 1"
set srcTblNam to "Table 1"
set tgtDocNam to "MyDocName2.numbers"
set tgtShtNam to "Sheet 1"
set tgtTblNam to "Table 1"

tell application "Numbers"
	tell document srcDocNam's sheet srcShtNam's table srcTblNam
		set vv to last row's cells's value -- places last row's values in AppleScript list
	end tell
	tell document tgtDocNam's sheet tgtShtNam's table tgtTblNam
		repeat with c from 1 to column count
			set last row's cell c's value to vv's item c
		end repeat
	end tell
end tell


Feb 1, 2019 9:00 AM in response to Apple_Script

This is based on the script I gave you in your previous post - SGill may have a version of his, which is probably more elegant.

The following assumes you start with both documents open, with 'Company Info' to the front.


tell application "Numbers"
	activate
	tell document 1
		tell sheet 1
			tell table 1
				set selection range to range "G1:G16"
			end tell
		end tell
	end tell
end tell

copyit()


tell application "System Events"
	tell process "Numbers"
		perform action "AXRaise" of window 2
	end tell
end tell


tell application "Numbers"
	activate
	tell document 1
		tell sheet 1
			tell table 2
				set selection range to range "C1"
			end tell
		end tell
	end tell
end tell

pasteit()

on copyit()
	tell application "System Events"
		tell application "Numbers" to activate
		keystroke "c" using {command down}
	end tell
end copyit

on pasteit()
	tell application "System Events"
		tell application "Numbers" to activate
		keystroke "v" using {command down}
	end tell
end pasteit


'AXRaise' brings the second document to the front. The script assumes that you know the row you want to copy in the Company Info document. If it is changing then selecting the bottom row involves counting the number of rows. I got as far as identifying the cell numbers at the beginning and end of the range:


tell table 1
				set rw to the row count as string
				set clmn to the column count as string


but this gives the number of the column across, not the letter and number which identifies it...

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.

Apple Script - Copy the second row of a table in numbers and paste it into the bottom line of a numbers table in another document

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