• 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: Mon, 25 May 2015 18:20:04 +0200

Hello Brian

As many components weren't available, I did my best to try to replace them.

When I tried to paste the chart after copying it from Numbers I got the result which you described.
So I decided to try to work with the chart stored in a file.
And bingo, it worked.

Here is the code which I used :

property numbersGraphPrint : true
property runForOz : true
property numbersGraphIncludeCompressedFile : true
property itemDetails : {"bof", "beurk"}
property saveTheFilePath : missing value
property theCCRecipients : {"email@hidden", "email@hidden"}
property displayHourlyJobsFlag : true
property PosixLogoPath : missing value
property PosixChartPath : missing value


set PosixLogoPath to POSIX path of ((path to desktop as text) & "mac-pro-overview-thunderbolt-2013.png")
set the_subject to "Hello there"
set the_body to "Please read the attached file:"
tell application "Mail"
set newMessage to make new outgoing message ¬
with properties {subject:the_subject, content:the_body, visible:true}
end tell
# Paste copied Numbers Chart
try
set p to 7
if (my numbersGraphPrint) then
# set (my numbersGraphPrint) to false
set p to 8
my setUpTallyNumbersChartCreator() # Sets up & copies Chart
tell current application to delay 2
tell application "Mail"
activate
tell application "System Events" to tell process "Mail"
set frontmost to true # ADDED for Yosemite
# In case cursor is in top address fields
repeat 7 times
keystroke tab
tell current application to delay 0.2
end repeat
keystroke return
set p to 9
keystroke (ASCII character 31) using command down # move to end of text
tell current application to delay 0.1
keystroke return
keystroke " "
keystroke return
keystroke " "
keystroke return
set p to 10
tell application "Mail" to activate
set p to 10.1
try
set p to 10.2
keystroke "v" using command down
keystroke return
set p to 10.3
tell current application to delay 1
end try
end tell
end tell
end if
if my runForOz then tell current application to delay 20 # image is being pasted
end try
try
set PosixFilePath to ""
if (my numbersGraphIncludeCompressedFile) and ("Hourly" is not in my itemDetails) then
set p to 11
tell application "Finder"
activate
set p to 12
select file (my saveTheFilePath)
end tell
set p to 13
tell current application to delay 0.2
tell application "System Events" to tell process "Finder"
set frontmost to true # ADDED for Yosemite
set p to 14
log name of menu item 20 of menu 1 of menu bar item 3 of menu bar 1
--> Compresser
click menu item 20 of menu 1 of menu bar item 3 of menu bar 1
set p to 15
set compressedFilePath to ((my saveTheFilePath as text) & ".zip" as text) as text
set p to 16
tell application "Finder"
repeat until exists file compressedFilePath
tell current application to delay 0.1
end repeat
set p to 17
set PosixFilePath to POSIX path of (compressedFilePath as text)
end tell
end tell
end if
end try
set p to 20
# Insert Attachments
tell application "Mail"
tell newMessage
set p to 6.1
try
repeat with themailitem in theCCRecipients
make new to recipient at end of to recipients with properties {address:themailitem}
end repeat
end try



try
make new attachment with properties {file name:PosixChartPath as POSIX file} at before the first paragraph
on error errmsg number errnum
tell application "System Events" to display dialog "eMailIt setting Logo error " & errmsg & " number " & errnum
end try


try
make new attachment with properties {file name:PosixLogoPath as POSIX file} at before the first paragraph
on error errmsg number errnum
tell application "System Events" to display dialog "eMailIt setting Logo error " & errmsg & " number " & errnum
end try
set p to 18
if PosixFilePath ≠ "" and (my displayHourlyJobsFlag) then
try
tell application "System Events" to tell process "Mail"
set frontmost to true # ADDED for Yosemite
keystroke (ASCII character 31) using command down # move to end of text
tell current application to delay 0.1
keystroke return
keystroke " "
keystroke return
end tell
make new attachment with properties {file name:PosixFilePath as POSIX file} at after the last attachment # OR, paragraph
if my runForOz then tell current application to delay 20 # replaces image
on error errmsg number errnum
tell application "System Events" to display dialog "eMailIt setting compressed File error " & errmsg & " number " & errnum
end try
set p to 19
end if
end tell
end tell

on setUpTallyNumbersChartCreator()
set spreadsheetPath to (path to desktop as text) & "4Brian.numbers"
set my saveTheFilePath to spreadsheetPath
set my PosixChartPath to POSIX path of ((path to desktop as text) & "theChart.png")
end setUpTallyNumbersChartCreator



I left the saving of the chart as an exercise which will be trivial for you.
I just wish to add a question and a comment : 

(1) Why use the Finder to zip the document when it's easy to achieve with a simple do shell script "ditto " which don't requires GUI Scripting ?
(2) You will see that I added three instructions : set frontmost to true 
which are required when we run under Yosemite.


Yvan KOENIG (VALLAURIS, France) lundi 25 mai 2015 18:19:56





 _______________________________________________
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

  • Follow-Ups:
    • Re: 'Make new attachment' dilemma
      • From: Brian Christmas <email@hidden>
References: 
 >'Make new attachment' dilemma (From: Brian Christmas <email@hidden>)

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