tell application "Microsoft Outlook" to activate
delay 0.5
tell application "Microsoft Outlook"
set selectedMsg to (current messages)
set selectedMsg to item 1 of result
set msgAttachment to attachments of selectedMsg
set msgAttachment to result's item 1
set attachmentName to name of msgAttachment
set attachmentFile to ((path to desktop) & attachmentName) as text
set submitfolder to "OS E:Users:e:Desktop:" as alias
set collectionfolder to ":Volumes:Data E:Consulting F&M:Telephone Switch Record" as alias
delay 1
--> save message to disk before we move it
save msgAttachment in file attachmentFile -- NB. 'file' specifier.
end tell
it used to work flawlessly under OS 10.13 and MSO 2011. Stopped working under OS10.13 and MSO 365.
The error I get is:
error "Can’t get item 1 of {}." number -1728 from item 1 of {}
I played around with it but cannot get it to work. Any tips?
Using the variable result often introduce difficult to trace errors.
I guess that what you wanted to achieve is what is coded below.
tell application "Microsoft Outlook" to activate
delay 0.5
tell application "Microsoft Outlook"
set selectedMsg to (current messages)
log point "1" -- ADDED
set selectedMsg to item 1 of selectedMsg -- EDITED
set msgAttachment to attachments of selectedMsg
log point "2"-- ADDED
set msgAttachment to msgAttachment's item 1 -- EDITED
set attachmentName to name of msgAttachment
set attachmentFile to ((path to desktop) & attachmentName) as text
set submitfolder to "OS E:Users:e:Desktop:" as alias
set collectionfolder to ":Volumes:Data E:Consulting F&M:Telephone Switch Record" as alias
delay 1
--> save message to disk before we move it
save msgAttachment in file attachmentFile -- NB. 'file' specifier.
end tell
Once again, the way you describe the reported error doesn’t help, because we can’t guess which instruction really issued it.
Here two instructions were able to return it : the two ones which I edited.
The two added log instructions would help.
If only “point 1” is logged we will know that set msgAttachment to attachments of selectedMsg failed
If “point 2” is logged before the crash, we will know that set msgAttachment to msgAttachment’s item 1 failed
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 20 juillet 2020 11:20:24
Good morning. I thought I had been clear, obviously not, so sorry.
This script takes an enclosed document from an email and puts it on the DT and from there in a folder. next if trashes the file from the DT.
I ran your script and get following.
tell application "Microsoft Outlook"
activate
get current messages
--> {}
(*point 1*)
Result:
error "Can’t get item 1 of {}." number -1728 from item 1 of {}
tell application "Microsoft Outlook"
activate
get current messages
end
If I read well, the code above return an empty list.
So there was no object available matching the description “current messages” when you ran your script.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 20 juillet 2020 12:29:37
Just glancing over, and noticed a malformed file path. It sounds like the script hasn’t reached this part in its execution yet, and the file path will probably self-correct. But just for thoroughness:
":Volumes:Data E:Consulting F&M:Telephone Switch Record" as alias
As far as I’m aware–and I’m not particularly an expert on HFS paths–absolute file paths don’t begin with a colon. I think there’s an AppleScript application (either Finder or SystemEvents) that will (or did) print paths to insertable USB drives as alias “:USB 1”, for instance, but I’ve been told that’s a no no.
The second characteristic of which I’m aware is that folder paths should end with a colon.
And, finally, absolutely file paths would typically begin with the name of the drive to which the file path relates. So, assuming your hard drive is called “Macintosh HD”, then one possible corrected form of the file path would be:
alias "Macintosh HD:Volumes:Data E:Consulting F&M:Telephone Switch Record:"
But it’s also evident you’re crossing over into another disk, so it can be shortened to this:
alias "Data E:Consulting F&M:Telephone Switch Record:"
Although I’ve just noticed your script doesn’t end up using it anyway, so blah.
as we used this script for about 10 years now I do nothing differently compared to before when it worked. the email is selected (as we always did) and it gives this error.
set selectedMsg to (current messages)
set msgAttachment to attachments of selectedMsg
--The above too works
set attachmentName to name of msgAttachment -- → error
-- → error "Can’t get name of {}." number -1728 from name of {}
I am not an expert, but I assume as many of you have already stated, it is not possible to select messages in Outlook Mac (365) in the current version due to sandbox restrictions. So every script will fail at the moment. If anybody knows a workaround or has a solution, please let us know.
This fails:
tell application "Microsoft Outlook"
set selectedMessages to selected objects -- this fails
return selectedMessages
end tell
This fails:
tell application "Microsoft Outlook"
set selectedMessages to selection -- this fails
return selectedMessages
end tell
And this fails:
tell application "Microsoft Outlook"
set selectedMessages to current messages -- this fails
return selectedMessages
end tell
I think selecting messages would be the base of fixing many many outlook-scripts here in the forum currently, but sadly no luck yet on my system. With your script I get this error message: “error “Can’t make missing value into type record.” number -1700 from missing value to record”. The missing value seems to be the sandbox problem.
Hi,
I did not use outlook at home, (at work use windows, and allowed to install on home (corporate licensing ) installed it to try pdf output functionality.
How very strange, it all worked when I posted on 21/05 about “path to file” in another post
but did not on 22/05 !