As always, you’re willing to help.
If it works on your Mac, then I suspect it’s a hardware problem. I think some clicking done with the Applescript Editor on my machine is faulty.
I’ve resorted to not using the ‘Save Attachments…” menu, and saved the attachments directly to a folder.
The attempt to use the ‘Select All’ menu is because that menu is also greyed out on my iMac, and I was testing it.
The main problem stems from the fact that when Applescript, or AsObjC, opens a Mail message on my machine, many menus are greyed out. If I manually click on one of the Attachments to select it, the menus appear. So, I was trying to programmatically select the first attachment, but not even trying to click on its position using the Finder would work, and Mail does not have a 'select' command.
I’ve lodged a bug, as I exhausted every avenue I could think of.
Perhaps if other scriptures tried the script, we could build up a list of Macs that are not clicking correctly programatically. Testers just need to nominate a Mailbox that has the first item as containing an attachment.
Your amended script, with English menus, is below.
set theMailBox to "* items to store" # drafts mailbox
set FileMenu to 3
set EditMenu to 4
set SelectAll to "Select All" #"Tout sélectionner"
set SaveAttachmentsMenu to true
tell application "Mail"
activate
set WindowCount to count of windows
open item 1 of messages of mailbox theMailBox
set x to 0
repeat # wait until the message is really open.
tell current application to delay 0.1
set x to x + 1
if x > 40 then exit repeat
if (count of windows) > WindowCount then exit repeat
end repeat
tell application "System Events" to tell process "Mail"
tell current application to delay 1
try
select scroll area 1 of window 1
click
end try
try
tell scroll area 1 of window 1
set {xPosition, yPosition} to position
set {xSize, ySize} to size
end tell
-- modify offsets if hot spot is not centered:
click at {xPosition + (xSize div 2), yPosition + (ySize div 2)}
display dialog (xPosition as text) & tab & yPosition --EDITED
on error errmsg
display dialog errmsg
end try
end tell # System Events…
tell current application to delay 0.2
tell application "System Events" to tell process "Mail"
set frontmost to true # BRING THE PROCESS AT FRONT
set mNames to name of menu items of menu 1 of menu bar item FileMenu of menu bar 1
(*
(01) Nouveau message,
(02) Nouvelle fenêtre de visualisation,
(03) Ouvrir le Message,
(04) missing value,
(05) Fermer,
(06) Fermer toutes les fenêtres,
(07) Enregistrer,
(08) Enregistrer sous…,
(09) Enregistrer comme modèle…,
(10) missing value,
(11) Joindre des fichiers…,
(12) Enregistrer les pièces jointes…, Coup d’œil sur les pièces jointes…, missing value, Importer des boîtes aux lettres…, missing value, Exporter au format PDF…, missing value, Imprimer…*)
set saveAttachmentsLoc to item 12 of mNames # French version
set saveAttachmentsLoc to "Save Attachments…” # English version
set SaveAttachmentsMenu to true # MUST BE DEFINED AT LEAST ONCE !
if exists menu item saveAttachmentsLoc of menu 1 of menu bar item FileMenu of menu bar 1 then
keystroke "a" using command down
repeat 3 times
set isEnabled to enabled of menu item saveAttachmentsLoc of menu 1 of menu bar item FileMenu of menu bar 1
log isEnabled
end repeat
if not isEnabled then say "attachments disabled"
click menu item SelectAll of menu 1 of menu bar item EditMenu of menu bar 1
set x to 0
try
click menu item saveAttachmentsLoc of menu 1 of menu bar item FileMenu of menu bar 1
end try
repeat until exists sheet 1 of window 1
tell current application to delay 0.1
set x to x + 1
if x = 40 then
set SaveAttachmentsMenu to false
exit repeat
end if
end repeat
end if
end tell
end tell
SaveAttachmentsMenu