So, I have files that are named as such: "Blink013_30_18_6/02_AM_.mp4" which is the timestamp of the video. However, when the video is saved from the cloud servers locally, the created/modified date is the date it was downloaded. I'm trying to change the created and modified date to what's in the file name. [the above example is Blink01 -- camera name, then the date and time: March_30_2018 at 6:02am.
2 Issues
1. When I drag that file onto my terminal to change the created/modified dates, the terminal actually sees the file name as Blink013_30_18_6:02_AM_.mp4. I know that Finder doesn't like the colon, but is it actually an alias? Not sure, as I need to use the colon in my script as you'll see.
- Code: Select all
setfile -d "3/30/2018 6:02 AM" -m "3/30/2018 6:02 AM" /Users/me/temp/Blink013_30_18_6:02_AM_.mp4
This works as expected when run in the terminal.
2. When I hard-cord the file as opposed to using theFile, the external AppleScript works fine, and even passes the new date back to Hazel as is evident via the logs: Hazel Alert: 3/30/2018 6/02 AM
[There's that slash instead of a colon.]
So, why isn't my script working when using theFile?
HARD-CODED filename
So, my script teases out the correct timestamp and passes it back to Hazel. The next step is to run a shell script that takes that date and runs the
- Code: Select all
setfile
- Code: Select all
Hazel Alert: 3/30/2018 6/02 AM
[Custom Message] Hazel Alert: 3/30/2018 6/02 AM
DEBUG: == script output ==
ERROR: invalid date/time
== End script output ==
[Error] Shell script failed: Error processing shell script on file /Users/me/temp/Blink013_30_18_6:02_AM_.mp4.
Shellscript exited with non-successful status code: 2
theFile filename
Here's the error I get when I use theFile instead of hard-coding the filename:
- Code: Select all
[Error] AppleScript failed: Error executing AppleScript on file /Users/dmayo/temp/_deer/Blink013_30_18_6:02_AM_.mp4.
OSAScript error: {
NSLocalizedDescription = "Can\U2019t get text 8 thru -1 of alias \"Macintosh HD:Users:me:temp:_deer:Blink013_30_18_6/02_AM_.mp4\".";
NSLocalizedFailureReason = "Can\U2019t get text 8 thru -1 of alias \"Macintosh HD:Users:me:temp:_deer:Blink013_30_18_6/02_AM_.mp4\".";
OSAScriptErrorAppAddressKey = "<NSAppleEventDescriptor: null()>";
OSAScriptErrorBriefMessageKey = "Can\U2019t get text 8 thru -1 of alias \"Macintosh HD:Users:me:temp:_deer:Blink013_30_18_6/02_AM_.mp4\".";
OSAScriptErrorMessageKey = "Can\U2019t get text 8 thru -1 of alias \"Macintosh HD:Users:me:temp:_deer:Blink013_30_18_6/02_AM_.mp4\".";
OSAScriptErrorNumberKey = "-1728";
OSAScriptErrorOffendingObjectKey = "<NSAppleEventDescriptor: 'obj '{ 'form':'rang', 'want':'ctxt', 'seld':'rang'{ 'star':'obj '{ 'form':'indx', 'want':'ctxt', 'seld':8, 'from':'ccnt'($$) }, 'stop':'obj '{ 'form':'indx', 'want':'ctxt', 'seld':-1, 'from':'ccnt'($$) } }, 'from':'obj '{ 'want':'alis', 'from':null(), 'form':'name', 'seld':'utxt'(\"Macintosh HD:Users:me:temp:_deer:Blink013_30_18_6/02_AM_.mp4\") } }>";
OSAScriptErrorRangeKey = "NSRange: {0, 0}";
}
DEBUG: Tapping error retry sequence
Here's my Hazel:
upon match
Run AppleScript getFileDate.scpt [Options: export var fullDateTime]
Display notification with pattern •fullDateTime
Run shell script embedded script
Set color label red
Here's the embedded shell script:
- Code: Select all
setfile -d fullDateTime -m fullDateTime $1
Here's the external AppleScript (again, if I use theFile, it fails, but if I hardcode the filename it works when running thru Hazel)
- Code: Select all
on hazelProcessFile(theFile)
-- set x to theFile
set x to "Blink013_30_18_6/02_AM_.mp4"
set xx to trim(x, 7)
set xxx to trim(xx, -5)
set xAr to splitText("_", xxx)
set arDate to items 1 through 2 of xAr -- 3, 30
set arYear to item 3 of xAr
set arYear to addToList(arYear, 1, "20") -- 20, 1 8
set theYear to joinList("", arYear)
set arFullDate to addToList(arDate, 3, theYear)
set fullDate to joinList("/", arFullDate) -- 3/30/2018
set arTime to items 4 through 5 of xAr -- 6:02, AM
set fullTime to joinList(" ", arTime) -- 6:02 AM
set spacer to " "
set fullDateTime to fullDate & spacer & fullTime -- 3/30/2018 6:02 AM
return {hazelOutputAttributes:{fullDateTime}}
end hazelProcessFile
on trim(t, n)
if n > 0 then
return text (n + 1) thru -1 of t
else
return text 1 thru (n - 1) of t
end if
end trim
on splitText(delimiter, someText)
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to delimiter
set output to text items of someText
set AppleScript's text item delimiters to prevTIDs
return output
end splitText
on addToList(theList, placeToInsert, whatToInsert)
set tot to count of items of theList
if placeToInsert is less than 1 then set placeToInsert to 1
if placeToInsert is greater than tot then
set end of theList to whatToInsert
set NL to theList
else
set n to placeToInsert
if placeToInsert is 1 then
set lis1 to {whatToInsert}
else
set lis1 to {}
repeat with i from 1 to n - 1
set end of lis1 to item i of theList
end repeat
set end of lis1 to whatToInsert
end if
repeat with i from n to number of items in theList
set end of lis1 to item i of theList
end repeat
set NL to lis1
end if
return NL
end addToList
on joinList(delimiter, someList)
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to delimiter
set output to "" & someList
set AppleScript's text item delimiters to prevTIDs
return output
end joinList
Any new directions for me to look would be welcomed. Thanks.