• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: 'Make new attachment' dilemma
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'Make new attachment' dilemma


  • Subject: Re: 'Make new attachment' dilemma
  • From: Yvan KOENIG <email@hidden>
  • Date: Tue, 26 May 2015 16:08:59 +0200

Thanks to Shane Stanley here is a version which no longer trigger an auxiliary application and reduce GUI scripting use to minimal one.

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)
set theCCRecipients to {"email@hidden"}
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

--=====

As is, it requires Yosemite but storing the jpegFromClipToPath handler in a library file would allow us to work under Mavericks too.

Yvan KOENIG (VALLAURIS, France) mardi 26 mai 2015 16:06:10




 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: 'Make new attachment' dilemma (From: Brian Christmas <email@hidden>)
 >Fwd: 'Make new attachment' dilemma (From: Brian Christmas <email@hidden>)
 >Re: 'Make new attachment' dilemma (From: Christopher Stone <email@hidden>)
 >Re: 'Make new attachment' dilemma (From: Brian Christmas <email@hidden>)

  • Prev by Date: Re: 'Make new attachment' dilemma
  • Next by Date: Re: Applescript counting mails keeps counting mail in other folders
  • Previous by thread: Re: 'Make new attachment' dilemma
  • Next by thread: Re: 'Make new attachment' dilemma
  • Index(es):
    • Date
    • Thread