Date From yyyymmddhhmmss Filename

Summary: Sets the creation dates of the selected records based on their filenames.
Requires: EagleFiler
Install Location: ~/Library/Scripts/Applications/EagleFiler/
Last Modified: 2019-10-02


This script looks for a date in the format 20140217074436 in each record’s filename and uses it to set the record’s creation date. This is useful, for example, if you have old scanned documents and want to set their dates (for sorting or searching purposes) based on the date of the document rather than the date of the scan.

Installation Instructions · Download in Compiled Format · Download in Text Format


tell application "EagleFiler"
set _records to selected records of browser window 1
repeat with _record in _records
set _date to my dateFromComponents(my dateComponentsFromFilename(_record's basename))
set _record's creation date to _date
end repeat
end tell

on dateComponentsFromFilename(_filename)
-- yyyymmddhhmmss
set _regex to "(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})"
set _script to "python -c \"import sys, re; print ' '.join('" & _regex & "', sys.argv[1]).groups())\" "
set _spaceSeparated to do shell script _script & _filename's quoted form
return words of _spaceSeparated
end dateComponentsFromFilename

on dateFromComponents(_components)
set _date to current date
set _date's year to item 1 of _components
set _date's month to item 2 of _components
set _date's day to item 3 of _components
set _hours to item 4 of _components
set _minutes to item 5 of _components
set _seconds to item 6 of _components
set _date's time to _hours * hours + _minutes * minutes + _seconds
return _date
end dateFromComponents