Automatische Umbenennung von Dateinamen

Ich bin beileibe kein AppleScript-Kenner, deshalb brauche ich bei Hilfe bei der Automatisierung eines Prozesses - wenn das überhaupt möglich ist:

Ich möchte erreichen, dass Dokumente (v.a. E-Mails), die in DEVONthink abgelegt wurden, automatisch umbenannt werden - und zwar nach folgendem Muster

“Erstellungsdatum (YY-MM-DD) - Absender > Empfänger Dokumentename/Betreff”

Gibt es eine Möglichkeit, das z.B. mit AppleScript umzusetzen?

Hier ist ein einfaches Skript, das Emails entsprechend umbenennen sollte:


tell application "DEVONthink Pro"
	set theSelection to the selection
	repeat with theRecord in theSelection
		set theDate to creation date of theRecord
		set theMD to meta data of theRecord
		
		try
			set theSubject to |kMDItemHeadline| of theMD
			if theSubject is missing value or theSubject is "" then error
		on error
			set theSubject to "No subject"
		end try
		
		try
			set theSender to |kMDItemAuthors| of theMD
			if theSender is missing value or theSender is "" then error
		on error
			set theSender to |kMDItemAuthorEmailAddresses| of theMD
		end try
		
		set theRecipient to |kMDItemRecipientEmailAddresses| of theMD
		set theName to (((year of theDate) as string) & "-" & ((month of theDate) as integer) as string) & "-" & ((day of theDate) as string)
		set theName to theName & " " & theSender & " > " & theRecipient & ": " & theSubject
		set name of theRecord to theName
	end repeat
end tell

Besten Dank - genau das, was ich brauche

Nun doch noch eine Nachfrage:

Das Script generiert Datumsangaben wie “2012-11-25”, bei einstelligen Daten jedoch in dieser Form: “2012-5-3”. Was muss ich an dem Script verändern, damit das Datum nicht so “2012-5-3”, sondern so: “2012-05-03” aussieht?

Das ist eine etwas größere Änderung:


tell application "DEVONthink Pro"
	set theSelection to the selection
	repeat with theRecord in theSelection
		set theDate to creation date of theRecord
		set theMD to meta data of theRecord
		
		try
			set theSubject to |kMDItemHeadline| of theMD
			if theSubject is missing value or theSubject is "" then error
		on error
			set theSubject to "No subject"
		end try
		
		try
			set theSender to |kMDItemAuthors| of theMD
			if theSender is missing value or theSender is "" then error
		on error
			set theSender to |kMDItemAuthorEmailAddresses| of theMD
		end try
		
		set theRecipient to |kMDItemRecipientEmailAddresses| of theMD
		set theName to ((year of theDate) as string) & "-" & my formattedNumber((month of theDate) as integer) & "-" & my formattedNumber(day of theDate)
		set theName to theName & " " & theSender & " > " & theRecipient & ": " & theSubject
		set name of theRecord to theName
	end repeat
end tell

on formattedNumber(theNumber)
	if theNumber < 10 then
		return "0" & (theNumber as string)
	end if
	return (theNumber as string)
end formattedNumber