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 & "test test" & return & 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 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 > 40 then
say "file does not exist"
exit repeat
end if
tell current application to delay 0.1
end repeat
set PosixFilePath to POSIX path of (compressedFilePath as text)
end tell
my setUpTallyNumbersChartCreator()
tell application "Finder"
set jpgFilePath to ((path to desktop) & "Numbers Chart.jpg" as text)
set PosixjpgFilePath to POSIX path of (jpgFilePath as text)
end tell
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
tell newMessage
set c to count of paragraphs
end tell
say c # says '7'
keystroke (ASCII character 31) using command down # move to end of text
tell current application to delay 0.1
repeat 4 times
keystroke return
keystroke "test1"
keystroke (ASCII character 31) using command down # move to end of text
end repeat
keystroke (ASCII character 31) using command down # move to end of text
end tell
tell newMessage
make new attachment with properties {file name:PosixjpgFilePath as POSIX file} at after the last paragraph
# OR, attachment
make new attachment with properties {file name:PosixFilePath as POSIX file} at after the last attachment
end tell
tell current application to delay 2 # allows the cursor to move back to 'To:' field
tell application "System Events" to tell process "Mail"
set frontmost to true # ADDED for Yosemite
repeat 7 times
keystroke tab
tell current application to delay 0.2
end repeat
keystroke return
keystroke (ASCII character 31) using command down # move to end of text
# tell current application to delay 10.2
tell newMessage
set c to count of paragraphs
end tell
say c # says '8'
repeat (c + 6) times
keystroke (ASCII character 31) using command down
keystroke return
keystroke "test2."
end repeat
tell newMessage
set c to count of paragraphs
end tell
say c # says '8'
end tell
tell newMessage
tell current application to delay 1
# This adds attachment just before last 'test2', but adding it removes the first two attachments
make new attachment with properties {file name:PosixFilePath as POSIX file} at after the last paragraph
end tell
tell newMessage
set c to count of paragraphs
end tell
say c # says '7'
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
end tell
end setUpTallyNumbersChartCreator