How to get the filename after a save command

Greetings readers,

I used the following Applescript command to save an email message (in Outlook) as a file in a special folder:

save objInSelection in myAttachmentsFolder

However, I don't know how to get the filename under which the message was saved. Any idea how?

Normally, the filename is the message subject after translating some characters (such as : to - ) and adding a suffix such as [1] if the original filename already exists. So for example, the first time a message titled "Re: WTC" was saved, its filename was "Re- WTC.eml". The second time it was "Re- WTC[1].eml".

So, the question is: how can I get the name of the file just saved?



Checking the file listing in the folder in which the file was saved and selecting the latest file does the job.

AppleScript's code to find the latest file in a folder is highly inefficient (coding-wise). But the shell command comes to the rescue:

set sLatestFilename to do shell script "ls -t " & myAttachmentsFolder & " | head -n 1"