apple script selection range

here is the script I use everyday that works great, but I feel could be cut in half if someone can help me how to figure out how to paste in cells "B2:E2" & "Z2:AA2" at the same time.


tell application "Numbers"


activate


tell document 1


tell sheet 3


tell table 1


set selection range to range "G2:J2"


end tell


end tell


end tell


end tell




copyit()




delay 1




tell application "Numbers"


activate


tell document 1


tell sheet 2


tell table 1


add row above second row


set selection range to range "A2"


end tell


end tell


end tell


end tell




delay 1




tell application "Numbers"


activate


tell document 1


tell sheet 2


tell table 1


set selection range to range "B2:E2"


end tell


end tell


end tell


end tell




delay 1




tell application "System Events"


tell application "Numbers" to activate


keystroke "v" using {command down}


end tell




delay 1












tell application "Numbers"


activate


tell document 1


tell sheet 3


tell table 1


set selection range to range "K2:L2"


end tell


end tell


end tell


end tell






copyit()




delay 1.5




tell application "Numbers"


activate


tell document 1


tell sheet 2


tell table 1


set selection range to range "Z2:AA2"


end tell


end tell


end tell


end tell




delay 1


tell application "System Events"


tell application "Numbers" to activate


keystroke "v" using {command down}


end tell





iMac (M3, 2023)

Posted on Jan 17, 2024 7:43 PM

Reply
1 reply

Jan 17, 2024 10:16 PM in response to SneakPeak01

Part of your script seems to be missing, e.g. copyit() seems to have no target function.


Below is a simple example where the values in range A2:B2 of Table 1 are copied to both A4:A4 and A10:B10.


You can vary the names within the lines at the top to suit your configuration, i.e. copy to different tables or sheets.


The script is easily modified to copy between documents if needed.


SG




copyIt("Sheet 1", "Table 1", "A2:B2")
pasteIt("Sheet 1", "Table 1", "A4:B4")
pasteIt("Sheet 1", "Table 1", "A10:B10")

to copyIt(shtName, tblName, rngName)
	tell application "Numbers"
		tell document 1
			tell table tblName of sheet shtName
				set selection range to range rngName
				tell application "Numbers" to activate
				tell application "System Events" to keystroke "c" using command down
			end tell
		end tell
	end tell
end copyIt

to pasteIt(shtName, tblName, rngName)
	tell application "Numbers"
		delay 0.1 -- may need to vary this
		tell document 1
			tell table tblName of sheet shtName
				set selection range to range rngName
				tell application "Numbers" to activate
				tell application "System Events" to keystroke "v" using command down
			end tell
		end tell
	end tell
end pasteIt




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 selection range

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