Hazel Script: reset archiveDate

This is the script for Hazel I discussed here:
- Code: Select all
(*
script to reset archiveDate to lastUsedDate
uses SpotMeta <http://www.fluffy.co.uk/spotmeta/>
intended to be run by a Hazelrule
*)
my hazelProcessFile(infile)
on hazelProcessFile(infile)
-- make input usable
set infile to quoted form of POSIX path of infile
-- read lastUsedDate
set lastUsedDate to do shell script "mdls -name kMDItemLastUsedDate " & infile
-- isolate date/time string
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "= "
set lastUsedDate to text item -1 of lastUsedDate
set AppleScript's text item delimiters to tid
set lastUsedDate to text 1 thru -7 of lastUsedDate
-- reformat in SpotMeta date format YYYYMMDDHHMMSS (unspecified chars default to 19700101120000)
-- just strip spaces and diacritics from lastUsedDate
set archiveDate to (words of lastUsedDate) as string
-- go reset archive date
set theCmd to "spotmeta set d:archiveDate=" & archiveDate & " " & infile
do shell script theCmd
end hazelProcessFile