Almost works. Modifies the filename as expected. But the first time through the script, the script also modifies the “Title” with _newName as well as the filename, even though the script doesn’t set the “title” parameter. If I correct the title by hand then rerun the script, it works.
I’m running this script, where I’ve switched the date around (but I noticed it doing it with the script exactly as I downloaded it from your site)
tell application "EagleFiler"
set _records to selected records of browser window 1
tell library document 1
repeat with _record in _records
set _base to _record's title
set _dateString to my dateStringFromDate(_record's creation date)
set _newName to _dateString & "-" & _base
set filename of _record to _newName
end repeat
end tell
end tell
on dateStringFromDate(_date) -- YYMMDD
set _shortyear to (text items 3 thru 4 of (year of _date as string)) as string
set _month to my pad((month of _date as integer) as string)
set _day to my pad(day of _date as string)
return _shortyear & _month & _day
end dateStringFromDate
on pad(_string)
if length of _string is 1 then
set _string to "0" & _string
end if
return _string
end pad
Before:
Date = “21/06/2008”
Title = “School Report”
Filename = “School Report.pdf”
After:
Date = “21/06/2008”
Title = “080621-School Report”
Filename = “080621-School Report.pdf”
If I manually correct the title, i.e. set Title = “School Report” and re-run it, the script functions. It is random. Sometimes it works and only renames Filename, sometimes it renames Title.
If the title and the filename start out the same, EagleFiler automatically propagates filename changes to the title so that they stay in sync. (This happens when manually renaming a file, not just with AppleScript.) If you don’t want it to do this, you could add a line to the end of the repeat such as:
Works great now - thanks. The working script to create the filename
YYMMDD-Title
from the file’s title and creation date, for anyone that wants to adopt my peculiar filing convention
tell application "EagleFiler"
set _records to selected records of browser window 1
tell library document 1
repeat with _record in _records
set _base to _record's title
set _dateString to my dateStringFromDate(_record's creation date)
set _newName to _dateString & "-" & _base
set filename of _record to _newName
set _record's title to _base
end repeat
end tell
end tell
on dateStringFromDate(_date) -- YYMMDD
set _shortyear to (text items 3 thru 4 of (year of _date as string)) as string
set _month to my pad((month of _date as integer) as string)
set _day to my pad(day of _date as string)
return _shortyear & _month & _day
end dateStringFromDate
on pad(_string)
if length of _string is 1 then
set _string to "0" & _string
end if
return _string
end pad