try
set the clipboard to ""
activate
tell current application to delay 0.1
tell document 1 to tell sheet 1
tell current application to delay 0.1
position of chart 1
tell current application to delay 10.2
tell application "System Events" to tell process "Numbers"
set frontmost to true
tell current application to delay 0.2
keystroke "c" using {command down}
end tell # System Events…
end tell # document…
on error errmsg
tell application "System Events" to display dialog "Saving jpg Chart image 1 " & errmsg
end try
end tell # Numbers
repeat
if (clipboard info) is not {{Unicode text, 0}, {string, 0}, {scrap styles, 2}, {«class utf8», 0}, {«class ut16», 2}, {scrap styles, 2}} then exit repeat
end repeat
set p2d to path to desktop as text
set fileName to "Numbers_Chart.jpg"
set pathToChart to (p2d & fileName)
set theResult to my jpegFromClipToPath:(POSIX path of pathToChart) compressFactor:1.0
# return pathToChart as alias
end setUpTallyNumbersChartCreator
#=====
# CAUTION : thePath must be a POSIX path !
on jpegFromClipToPath:thePath compressFactor:compFactor -- 0.0 = max compression, 1.0 = none
try
set pb to current application's NSPasteboard's generalPasteboard() -- get pasteboard
set theData to pb's dataForType:"public.tiff" -- get tiff data off pasteboard
if theData = missing value then error "No tiff data found on clipboard"
set newRep to current application's NSBitmapImageRep's imageRepWithData:theData
set theData to (newRep's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:compFactor, NSImageProgressive:false})
say 18
set theResult to (theData's writeToFile:thePath atomically:true)
say theResult as text
return (theResult = 1)
on error errmsg
tell application "System Events" to display dialog "jpegFromClipToPath " & errmsg
end try
end jpegFromClipToPath:compressFactor:
On 27 May 2015, at 2:55 am, Yvan KOENIG <
email@hidden> wrote:
Hello
In fact your instruction used to select a chart is too complicated 😉
Grabbing at least one of the three properties tested below is sufficient.
tell application "Numbers" to tell document 1 to tell sheet 1
position of chart 1
end tell
tell application "Numbers" to tell document 1 to tell sheet 1
width of chart 1
end tell
tell application "Numbers" to tell document 1 to tell sheet 1
height of chart 1
end tell
Grabbing its class, locked or parent doesn't select the object.
Yvan KOENIG (VALLAURIS, France) mardi 26 mai 2015 18:55:50