Unfortunately I still get the same results.
I’ve attached a simplified version of my script, it just needs the path to the compressed file to be set, and an open numbers document with a Chart.
It’s as though Mail is not recognising that an image has been pasted, and needs to be forced to update. I’ve tried doing that with two separate calls to Mail, to no avail.
property saveTheFilePath : ((path to desktop) & "MM Numbers Chart Files: Weekly Tally (Current Week):2015 5 (May) 25 Saved 2015 525 20 59 28 Weekly Tally (Current Week).numbers" as text)
my setUpMessage()
on setUpMessage()
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}
set compressedFilePath to ((my saveTheFilePath as rich text) & ".zip" as rich text) as rich text
set p to 16
set x to 0
tell application "Finder"
repeat until exists file compressedFilePath
set x to x + 1
tell current application to delay 0.1
if x > 20 then exit repeat
tell current application to delay 0.1
end repeat
set p to 17
set PosixFilePath to POSIX path of (compressedFilePath as text)
end tell
my setUpTallyNumbersChartCreator()
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
tell current application to delay 0.2
set p to 9
keystroke (ASCII character 31) using command down # move to end of text
keystroke return
keystroke " "
keystroke return
keystroke " "
keystroke return
tell current application to delay 0.1
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 & " " & return & " " & return as text)
set p to 10.3
tell current application to delay 10 # Chart is definitely added
end try
end tell
end tell
tell application "Mail"
activate
tell newMessage
make new attachment with properties {file name:PosixFilePath as POSIX file} at after the last paragraph
# OR, attachment
end tell
end tell
end setUpMessage
on setUpTallyNumbersChartCreator()
tell application "Numbers"
activate
tell document 1
tell current application to delay 0.2
tell sheet 1
set width of chart 1 to (width of chart 1)
tell current application to delay 0.2
tell application "System Events" to tell process "Numbers"
click menu item "Copy" of menu 1 of menu bar item "Edit" of menu bar 1
end tell
tell current application to delay 1
end tell
end tell
# quit saving no
end tell
tell application "Preview"
activate
tell current application to delay 0.4
tell application "System Events" to tell application process "Preview"
set nbw to count windows
(* Trigger the menu item "File > New from Clipboard" *)
keystroke "n" using {command down}
(* Wait the availability of the new PDF window *)
repeat while nbw = (count windows)
delay 0.2
end repeat
(* Get the name of the new window *)
set WindowName to name of window 1 --(first window whose subrole is "AXStandardWindow")
keystroke "s" using {command down}
(* Wait the availability of the Save sheet *)
repeat until exists sheet 1 of window WindowName
delay 0.2
end repeat
tell sheet 1 of window WindowName
-- properties of every UI elements
tell group 1
click first pop up button
delay 0.2
-- properties of every menu item of menu 1 of first pop up button
click menu item "JPEG" of menu 1 of first pop up button
delay 0.2
end tell -- group
delay 0.4
keystroke "Numbers Chart"
click pop up button 1
click menu item "Desktop" of menu 1 of pop up button 1
delay 0.2
click button 1 (* Click in the Save button *)
delay 0.2
try
click button 1 of sheet 1 # 'Replace' button
end try
delay 1 # Allow time to save before closing
end tell -- sheet
end tell -- System Events
close window 1 saving no
open ((path to desktop) & "Numbers Chart.jpg" as text)
tell application "System Events" to tell application process "Preview"
delay 0.2
keystroke "c" using command down
end tell
close window 1 saving no
end tell
end setUpTallyNumbersChartCreator