Numbers clipboard reference vs data

I am trying to programatically add a numbers chart to the clipboard so I can paste it into another document.


tell application "Numbers"
	set myChart to chart 1 of active sheet of document 1
	set the clipboard to myChart
	return the clipboard
end tell

→ {reference:chart 1 of sheet 1 of document id “F064AF04-3B9D-4B1A-90BE-598F58C09ADE” of application “Numbers”}

This script add a reference to the clipboard and will not let me paste it into another document.

Manually selecting the chart, copying it, and returning the clipboard returns:
{«class PNGf»:«data PNGf895xxxxxxxxxxxxD5»}

Or in SD:

Manually copying to the clipboard does let me paste it into another document.

How can I put the data into the clipboard rather than a reference to the chart?

You may try :

tell application "Numbers" to tell document 1 to tell active sheet
	set aChart to chart 1
	# Select the chart
	set itsPosition to position of aChart
	tell application "System Events" to tell process "Numbers"
		set frontmost to true
		keystroke "c" using {command down}
	end tell
end tell

Yvan KOENIG running El Capitan 10.11.3 in French (VALLAURIS, France) jeudi 25 février 2016 16:51:33

That is sneaky… I love it. Thanks Yvan

As far as I know, it’s not documented so maybe it will be broken sometimes.
In fact when I discovered that, I was on the road to use cliclick to click in the chart to select it.
Take care to try if it behave well if the chart is not in the visible area when you call it.

It’s puzzling. When the chart is not visible, the script works flawlessly but when I change the area to display, the chart is not flagged as selected.

Yvan KOENIG running El Capitan 10.11.3 in French (VALLAURIS, France) jeudi 25 février 2016 17:21:30