Imported from the Apple Support Forums via the Wayback Machine 🔗
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."
Imported from the Apple Support Forums via the Wayback Machine 🔗
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.
tellapplication"Numbers"activatetell document 1tell sheet 1tell table 1set selection range to range "G1:G16"endtellendtellendtellendtell
copyit()
tellapplication"System Events"tell process "Numbers"
perform action "AXRaise"of window 2endtellendtelltellapplication"Numbers"activatetell document 1tell sheet 1tell table 2set selection range to range "C1"endtellendtellendtellendtell
pasteit()
on copyit()
tellapplication"System Events"tellapplication"Numbers"toactivate
keystroke "c" using {command down}
endtellend copyit
on pasteit()
tellapplication"System Events"tellapplication"Numbers"toactivate
keystroke "v" using {command down}
endtellend 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 rowcountasstringset clmn to the columncountasstring
but this gives the number of the column across, not the letter and number which identifies it...
0
Apple_Script·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Just out of interest, at the moment it keeps pasting the data into the header column of the table - is there a way to adjust it so that it just pastes into the selected row?
I'm trying to identify the part of the code which changes the location of the paste - is it the "set selection range to range "C1"?
0
Apple_Script·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Fantastic, Thank you
Thank you very much for your help today gentlemen - There are still a couple of very minor changes I'd like to make to the automator tool, but you've been invaluable today. Thank you for your quick replies!
All the best
0
SGIII·
Imported from the Apple Support Forums via the Wayback Machine 🔗
copythe lowest line onthe table "Company Info" (photos below) and paste itonthethe 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 documentsset 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 tolastrow's cells's value-- places last row's values in AppleScript listend tell
tell document tgtDocNam's sheet tgtShtNam's table tgtTblNam
repeatwith c from1tocolumncountsetlastrow's cell c's valueto vv's item c
end repeat
end tell
end tell
0
Apple_Script·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Perfecto, Thank you ever so much!
0
Roger Wilmut1·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Good - evidently you know the addresses of the bottom row - just as well because the process of detecting them was getting messy.
0
Roger Wilmut1·
Imported from the Apple Support Forums via the Wayback Machine 🔗
'C1' was fictitious, I was just showing what the script would look like. Judging by your image it should be A3.