G’day scripters
I have a large ASObjC project that I’ve struck a problem with.
The Mail GUI interface seems not to accept addressing it, but throws an ‘Invalid index’ error.
Would any of you kind folk run the attached script and let me know if it errors, or if I’ve made any scripting mistakes, please?
Regards
Santa
property printDateTimeName : "2015 12 12 121212Z"
tell application "Mail"
activate
set exitLoop to false
set theMailBoxes to mailboxes as list
repeat with eachMailbox in theMailBoxes
if (count of message in eachMailbox) > 0 then
repeat with eachMessage in (messages of eachMailbox as list)
set tempAttachments to eachMessage's mail attachments
if (count of tempAttachments) > 0 then
set exitLoop to true
exit repeat
end if
end repeat
end if
if exitLoop then exit repeat
end repeat
open eachMessage
tell current application to delay 0.2
set p to 1
tell application "System Events" to tell process "Mail"
set p to 2
click menu item "Save As." of menu 1 of menu bar item "File" of menu bar 1
set x to 0
end tell
tell application "System Events" to tell process "Mail"
tell current application to delay 0.2
tell sheet 1 of window 1
set p to 4
try
set x to 0
set insertText to (my printDateTimeName & ".rtf" as text)
set insertTextEmergency to (my printDateTimeName as text)
set p to 6
try
set value of text field 1 to insertText
on error
keystroke insertTextEmergency
end try
tell current application to delay 0.1
do shell script "sleep 0.1"
set p to 7
# This keystroke opens desktop path
set p to 7.1
keystroke "d" using {command down, shift down}
tell current application to delay 0.1
try
if value of checkbox 1 of group 1 = 1 then click checkbox 1 of group 1
end try
set p to 8
tell group 1 to tell pop up button 1
click
set x to 0
repeat until exists menu 1
set x to x + 1
if x ≥ 15 then exit repeat
tell current application to delay 0.1
end repeat
try
click menu item 3 of menu 1
end try
do shell script "sleep 0.2"
set x to 0
end tell
set p to 9
click button 1
on error errmsg
tell application "System Events" to display dialog errmsg & " p = " & p
end try
tell current application to delay 0.2
# If can't save as rtfd, then dialog pops up as 'window 1'
try
tell window 1
click button "Use .rtf"
end tell
end try
end tell
end tell
end tell
Model: Late 2014 retina i7, Yosemite
AppleScript: 2.4
Browser: Safari 600.2.5
Operating System: Other