use scripting additions
use framework "Foundation"
use framework "AppKit"
set saveTheFilePath to (path to desktop as text) & "4Brian.numbers"
set pathToChart to my setUpTallyNumbersChartCreator() # get an alias
set compressedFilePath to my zipIt(saveTheFilePath) # get an alias
set pathToLogo to (path to desktop as text) & "mac-pro-overview-thunderbolt-2013.png"
my setUpMessage(pathToChart, compressedFilePath, pathToLogo as alias)
on setUpMessage(pathToChart, compressedFilePath, pathToLogo)
tell application "Mail"
activate
set p to 4
set the_content to ("test" & return & "test2" & return & return & return & return as rich text)
set newMessage to make new outgoing message with properties {visible:true, subject:"test", content:the_content}
tell newMessage
repeat with themailitem in theCCRecipients
make new to recipient at end of to recipients with properties {address:themailitem}
end repeat
make new attachment at end of last paragraph of content with properties {file name:pathToChart}
make new attachment at end of last paragraph of content with properties {file name:compressedFilePath}
make new attachment at end of last paragraph of content with properties {file name:pathToLogo}
# OR, attachment
end tell
end tell
end setUpMessage
on setUpTallyNumbersChartCreator()
set the clipboard to ""
tell application "Numbers"
activate
tell document 1 to tell sheet 1
set width of chart 1 to (width of chart 1)
tell application "System Events" to tell process "Numbers"
set frontmost to true
keystroke "c" using {command down}
end tell # System Events…
end tell # document…
# quit saving no
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 "theChart.jpg"
set pathToChart to (p2d & fileName)
set theResult to my jpegFromClipToPath:(POSIX path of pathToChart) compressFactor:1.0
--log "theResult = " & theResult
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
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})
set theResult to (theData's writeToFile:thePath atomically:true)
return (theResult = 1)
end jpegFromClipToPath:compressFactor:
--=====
on zipIt(fichier) (* fichier may be an alias *)
local Nom, ext, dossier, nomZip, source, dest
tell application "System Events" to tell disk item (fichier as text)
set Nom to name
set ext to name extension
set dossier to path of container
end tell -- System Events
set source to quoted form of POSIX path of (fichier)
set Nom to text 1 thru -(2 + (count of ext)) of Nom
set nomZip to Nom & ".zip"
set dest to dossier & nomZip
do shell script "ditto -ck " & source & " " & quoted form of POSIX path of dest
return dest as alias
end zipIt
--=====