Changing modification date in saved file doesn't work!!

Hello,

I’ve a script that saves emails in a folder. In the script I’m trying to change the modification date, but that doesn’t work.
Everything works fine. The file is saved in the wright place but the modification date hasn’t changed. It automaticly gets the date of today.

set rootFolder to "iMac G5 HD:users:Fons:documents:Outlook Archive:"

tell application "Microsoft Entourage"
	set fileThese to the selection
	repeat with fileThis in fileThese --repeat with every message currently selected 
		set thisFolder to the name of storage of fileThis --get the name of the folder this email is stored in 
		try
			set saveHere to rootFolder & thisFolder as alias --see if the folder exists in the Finder 
			set messageDate to the time sent of fileThis
			set receivedDate to the time received of fileThis
			--set messageDateAsString to receivedDate as string
			--display dialog messageDateAsString
			set theSender to the sender of fileThis --get the sender of the email 
			set theRecip to the address of recipient 1 of fileThis
			set recipAddress to address of theRecip
			set commentText to "From: " & address of theSender & return & "To: " & recipAddress as text 
			
			--if it does not fail, save the email to the folder 
			set savedFile to save fileThis in saveHere --this line would not work for me unless I removed the text "set savedFile to", but I am on an older OS at home 
			set subFolder to rootFolder & thisFolder & ":" as string
			tell application "Finder"
				--	display dialog commentText --String
				--	set the modification date of the last file of folder subFolder to messageDate
				set the modification date of the last file of folder subFolder to receivedDate
			end tell
		end try
	end repeat
end tell

And is it possible to get the subject and put it in the comment of the file?
Something like:

			set commentText to Subject &"From: " & address of theSender & return & "To: " & recipAddress as text

Thanks in advange

You should never rely on the Finder returning files in a specific order. Therefore it’s entirely likely that:

            set the modification date of the last file of folder subFolder to receivedDate 

is changing a file you don’t expect - probably (but not necessarily) the last file when listed alphabetically.

As for the comment you do it by simply:

 set comment of thefile to commentText

once you’ve correctly identified theFile, of course.

That´s just the problem, he doesn´t change anything. There is only one file in that folder
The scrip puts the file in that folder and gives it the name of the subject with “.eml” behind it. But it doesn´t change the date or name.
:frowning:

Isn’t there anybody who can help me??

The problem may be the way that you reference the file. I seem to recall that when there is exactly one file in a folder, there are problems related to ‘first’ and ‘last’ and so forth.

Can you refer to the file directly?

set the modification date of (“MacintoshHD:etc:etc:etc” as alias) to receivedDate

Andy

Since it’s Entourage that’s doing the saving, it’s possible that the Finder doesn’t immediately know of the file’s existence. It’s worth getting the Finder to ‘update’ the folder before it tries to access any files in it. That said, this may only be necessary when using a Finder reference (such as ‘last file of folder subFolder’) to access the file. Andy’s direct alias idea might work without the need for an update.

When testing code that’s in a ‘try’ block, it’s a good idea to put in an ‘on error’ section that displays a message. That way, if something doesn’t work, the script itself might tell you why:

         -- Blah blah blah
         set savedFile to ((saveHere as string) & fileThis & ".eml") as alias
         tell application "Finder"
            -- update saveHere
            set the comment of savedFile to commentText
            set the modification date of savedFile to receivedDate
         end tell
      on error errmsg
        display dialog errmsg
      end try
   end repeat
end tell

When I try this, I get the error on the line:

set savedFile to ((saveHere as string) & fileThis & ".eml") as alias

The error is: “Can’t make <> id 237 of application “Miscrosoft Entourage” into a string”
So this doesn’t work :cry:

So I’ve tried it and it works.
But the name of the email is always different.

Is there a way to refer to the file with the used variables??

Oke, now it works for the date:

		tell application "Finder"
			set subFolder to rootFolder & thisFolder & ":" as string
			set the modification date of the last file of folder subFolder to receivedDate
			set the comment of the last file of folder subFolder to commentText
		end tell

So it seems that

	set subFolder to rootFolder & thisFolder & ":" as string

was on the wrong place.

But I’m still not able to change the name of the file:

	set the comment of the last file of folder subFolder to commentText

Does not work :cry:
And neither does this:

set comment of thefile to commentText

It works!! :smiley:

:oops: :oops: I thought :oops: that I was changing the name :oops: but I changed the comment :oops: and suddenly I realised it. :oops: :oops:

Thanks everybody :smiley:

Sorry. My booboo. :oops: ‘fileThis’ is a reference to one of your e-mails in Entourage. What’s actually required is the email’s subject so that you can derive the name of the saved file. I don’t have Entourage, but it’s probably something like this:

set theSubject to the subject of fileThis
set savedFile to ((saveHere as string) & theSubject & ".eml") as alias

:smiley: Thanks everybody, it works great :smiley: