I've been trying to figure out how to use the touch command to change the creation date of a file (see here:
http://www.noodlesoft.com/forums/viewtopic.php?f=4&t=2960) and I stumbled upon this thread and I got to thinking:
Instead of asking Hazel to look inside the contents of a file for a date pattern,
couldn't I ask Hazel to look in the file name for a date pattern and use that with the Hazel and shell script attributes in the posts above? Since Hazel can change the name to the creation date, this may be the perfect solution for me to "carry forward" the creation date through a video conversion and then "put it back" when I'm finished.
So here's my starting file: 2013.11.17_17.22.36.m4v

Hazel renamed the file from a generic.MTS file that was created on Nov. 17, 2013 at 5:22.36pm
And then I try the solutions posted in this thread.
Here are my Hazel attributes:

Here are the details of those attributes:
- Code: Select all
if (all)
kind is movie
name matches date pattern (in format YYYY.MM.DD_hh.mm.ss)
I then set the following to happen once the file is matched:
First:
- Code: Select all
Rename with pattern Date Pattern, in format YYYY-MM-DD-hh-mm-ss)-(extension)
I'm not clear on the "-" between the (Date Pattern) and (extension), so I've put a "dash" as you see it above in between those two items in (); not sure if that was supposed to be a space, or whether the "dash" should follow "ss" in the Date Pattern.
Second:
- Code: Select all
Run shell script embedded script
- Code: Select all
filename_without_path=$(basename "$1")
extension="${filename_without_path##*.}"
filename_without_extension_or_path="${filename_without_path%.*}"
YYYY=$(echo "$filename_without_extension_or_path" | awk -F "-" '{print $1}')
MM=$(echo "$filename_without_extension_or_path" | awk -F "-" '{print $2}')
DD=$(echo "$filename_without_extension_or_path" | awk -F "-" '{print $3}')
hh=$(echo "$filename_without_extension_or_path" | awk -F "-" '{print $4}')
mm=$(echo "$filename_without_extension_or_path" | awk -F "-" '{print $5}')
ss=$(echo "$filename_without_extension_or_path" | awk -F "-" '{print $6}')
touch -t "$YYYY$MM$DD$hh$mm$ss" "$1")
Third:
- Code: Select all
Rename with pattern Date Pattern, in format YYYY.MM.DD_hh.mm.ss) (name) (extension)
Hazel finds
2013.11.17_17.22.36.m4v and renames it to
2013-11-17-17-22-36-.m4v yet the script fails with the following error:
- Code: Select all
2013-11-24 16:17:32.627 hazelworker[50159] DEBUG: Unexpected type for Mail download URL: (null)
2013-11-24 16:17:32.668 hazelworker[50159] DEBUG: Could not scan past browser.download.dir preference
2013-11-24 16:17:33.201 hazelworker[50159] Processing folder TempOutput (forced)
2013-11-24 16:17:33.201 hazelworker[50159] DEBUG: Initialized
2013-11-24 16:17:33.201 hazelworker[50159] DEBUG: Pausing to wait for things to settle down.
2013-11-24 16:17:35.201 hazelworker[50159] DEBUG: Processing directories: (
"/Volumes/HTPC/Media/Movies/AVCHD/TempOutput"
)
2013-11-24 16:17:35.224 hazelworker[50159] DEBUG: About to process directory /Volumes/HTPC/Media/Movies/AVCHD/TempOutput
2013-11-24 16:17:35.226 hazelworker[50159] DEBUG: Received file event: {
abort = 1;
}
2013-11-24 16:17:35.228 hazelworker[50159] DEBUG: .DS_Store: File is hidden/invisible. Skipping.
2013-11-24 16:17:35.430 hazelworker[50159] 2013.11.17_17.22.36.m4v: Rule Set Creation Date to Match Name matched.
2013-11-24 16:17:35.430 hazelworker[50159] DEBUG: New rule signature. Executing actions.
Old signature: (null)
New Signature:{typeObject isType: "public.movie" AND displayBasename hazelMatchesPattern: {{hazelcustomtoken:Date Pattern:({year:sc0:cap}:.:{month:sc0:cap}:.:{dayOfMonth:sc0:cap}:_:{hour:sc0:cap}:.:{minute:sc0:cap}:.:{second:sc0:cap}):cap}}}:{(rename:(
"{hazelcustomtoken:Date Pattern:({year:cd4}:-:{month:cd2}:-:{dayOfMonth:cd2}:-:{hour:cd2:uaf1}:-:{minute:cd2}:-:{second:cd2})}",
"-",
"{extension:sc0}"
),{
})(shellscript:/bin/bash:844d663f3786103870ea953f8eb3b615,{
})(rename:(
"{hazelcustomtoken:Date Pattern:({year:cd4}:{month:cd2}:{dayOfMonth:cd2}:_:{hour:cd2:uaf1}:{minute:cd2}:{second:cd2})}",
"{name:sc0}",
"{extension:sc0}"
),{
})}
2013-11-24 16:17:35.790 hazelworker[50159] [File Event] File renamed: /Volumes/HTPC/Media/Movies/AVCHD/TempOutput/2013.11.17_17.22.36.m4v renamed to /Volumes/HTPC/Media/Movies/AVCHD/TempOutput/2013-11-17-17-22-36-.m4v.
2013-11-24 16:17:36.805 hazelworker[50159] DEBUG: == script output ==
touch: out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]
== End script output ==
2013-11-24 16:17:36.805 hazelworker[50159] [Error] Shell script failed: Error processing shell script on file /Volumes/HTPC/Media/Movies/AVCHD/TempOutput/2013-11-17-17-22-36-.m4v.
2013-11-24 16:17:36.806 hazelworker[50159] Shellscript exited with non-successful status code: 1
2013-11-24 16:17:36.806 hazelworker[50159] DEBUG: Tapping error retry sequence
2013-11-24 16:17:36.820 hazelworker[50159] DEBUG: Writing out DB file: /Volumes/HTPC/Media/Movies/AVCHD/TempOutput
2013-11-24 16:17:36.872 hazelworker[50159] DEBUG: Directory /Volumes/HTPC/Media/Movies/AVCHD/TempOutput processed in 1.647401 seconds
2013-11-24 16:17:36.872 hazelworker[50159] DEBUG: Sleeping
2013-11-24 16:17:38.970 hazelworker[50159] DEBUG: About to process directory /Volumes/HTPC/Media/Movies/AVCHD/TempOutput
2013-11-24 16:17:38.971 hazelworker[50159] Received abort event.
2013-11-24 16:17:38.972 hazelworker[50159] DEBUG: Sending metrics to scheduler. Next scheduled run:
2013-11-24 16:17:38.973 hazelworker[50159] Done processing folder TempOutput
Any ideas and/or suggestions? I'm so close I can feel it!
Many thanks!!