{"id":777,"date":"2018-11-24T11:24:45","date_gmt":"2018-11-24T18:24:45","guid":{"rendered":"http:\/\/10.0.1.201\/?p=777"},"modified":"2018-11-24T11:24:45","modified_gmt":"2018-11-24T18:24:45","slug":"copy-video-create-date-from-original-file","status":"publish","type":"post","link":"https:\/\/strawhousepig.net\/wordpress\/2018\/11\/24\/copy-video-create-date-from-original-file\/","title":{"rendered":"Copy video create date from original file"},"content":{"rendered":"<p>This is the companion script for: <a href=\"http:\/\/strawhousepig.net\/video-re-encode-script\/\">Video re-encode script<\/a><\/p>\n<p>It uses <strong><a href=\"https:\/\/www.sno.phy.queensu.ca\/~phil\/exiftool\/\">exiftool<\/a><\/strong> to copy the video date atom(s) and <strong>setfile<\/strong> (is or was included with Apple&#8217;s Developer Tools) to change the file system dates. It will more than likely throw exiftool &#8220;File not found&#8221; errors and I&#8217;m not quite sure why. It has never failed to actually work despite this in my experience, however be very careful to not use this on your original source videos.<\/p>\n<p>Hopefully the settings and prompts make sense.<\/p>\n<p><code>(* http:\/\/strawhousepig.net\/<\/p>\n<p>This uses Apple's command line developer tools command 'setfile' to set the filesytem dates.<\/p>\n<p>https:\/\/developer.apple.com\/download\/more\/<\/p>\n<p>I believe an Apple Developer account is required for that, but I am not sure.<\/p>\n<p>Uses 'exiftool' to set track date atoms.<\/p>\n<p>https:\/\/www.sno.phy.queensu.ca\/~phil\/exiftool\/<\/p>\n<p>*)<\/p>\n<p>-- Set to 'false' to omit initial dialog prompts. Does not affect final confirmation prompt.<br \/>\nproperty prompt_me : true<\/p>\n<p>-- UTC timezone. Leave blank (\"\") to not use the timezone setting.<br \/>\nproperty tzone : \"-8:00\"<\/p>\n<p>on run<br \/>\n\tdo_it(false)<br \/>\nend run<\/p>\n<p>on do_it(redo)<br \/>\n\trepeat<br \/>\n\t\tif tzone is not \"\" then set tzone to \"-timezone=\\\"\" & tzone & \"\\\" \" -- There is a trailing space here.<br \/>\n\t\tif prompt_me is true then<br \/>\n\t\t\tif button returned of (display dialog \"Choose a TARGET file to set creation and modification dates of.\") is \"OK\" then<br \/>\n\t\t\t\tset newfile to choose file with prompt \"Select TARGET file to set creation and modified dates of:\"<br \/>\n\t\t\tend if<br \/>\n\t\telse<br \/>\n\t\t\tset newfile to choose file with prompt \"Select TARGET file to set creation and modified dates of:\"<br \/>\n\t\tend if<\/p>\n<p>\t\tset filepath to newfile as string<br \/>\n\t\tif prompt_me is true then<br \/>\n\t\t\tif button returned of (display dialog \"Choose a SOURCE file to *get* creation and modification dates from.\") is \"OK\" then<br \/>\n\t\t\t\tset oldfile to choose file with prompt \"Select SOURCE file to get dates from: \" & filepath<br \/>\n\t\t\tend if<br \/>\n\t\telse<br \/>\n\t\t\tset oldfile to choose file with prompt \"Select SOURCE file to get dates from: \" & filepath<br \/>\n\t\tend if<br \/>\n\t\tset newfilename to name of (info for of newfile)<br \/>\n\t\tif newfilename is not (name of (info for of oldfile)) then<br \/>\n\t\t\tset warn_button to button returned of (display alert \"File names do not match. Proceed?\" as warning buttons {\"Cancel\", \"Start Over\", \"Proceed\"})<br \/>\n\t\t\tif warn_button is \"Cancel\" then<br \/>\n\t\t\t\treturn<br \/>\n\t\t\telse<br \/>\n\t\t\t\tif warn_button is \"Start Over\" then<br \/>\n\t\t\t\t\tset redo to true<br \/>\n\t\t\t\t\texit repeat<br \/>\n\t\t\t\tend if<br \/>\n\t\t\tend if<br \/>\n\t\tend if<br \/>\n\t\ttell application \"System Events\" to set [c_date, m_date] to [creation date of oldfile, modification date of oldfile]<br \/>\n\t\tset [p_date_c, p_date_m] to [c_date, m_date] -- Saving \"pretty\" date for dialog prompt.<br \/>\n\t\tset c_date to ((month of c_date as integer) & \"\/\" & day of c_date & \"\/\" & year of c_date & \" \" & hours of c_date & \":\" & minutes of c_date & \":\" & seconds of c_date) as string<br \/>\n\t\tlog c_date<br \/>\n\t\tset m_date to ((month of m_date as integer) & \"\/\" & day of m_date & \"\/\" & year of m_date & \" \" & hours of m_date & \":\" & minutes of m_date & \":\" & seconds of m_date) as string<br \/>\n\t\tlog m_date<br \/>\n\t\tif button returned of (display dialog \"This will set the creation and modification dates of file \" & filepath & \" to:\" & return & return & p_date_c & return & p_date_m & return & return & \"Proceed?\") is \"OK\" then<br \/>\n\t\t\ttry<br \/>\n\t\t\t\t-- Have to include full path to exiftool binary because AppleScript uses the Bourne shell which doesn't have \/usr\/local\/bin in its path? *rolls eyes*<br \/>\n\t\t\t\tdo shell script \"\/usr\/local\/bin\/exiftool \" & tzone & \"-*date=\\\"`\/usr\/local\/bin\/exiftool -time:CreateDate \" & quoted form of POSIX path of oldfile & \"`\\\" -wm w \" & quoted form of POSIX path of newfile<br \/>\n\t\t\ton error theErr<br \/>\n\t\t\t\t-- Will throw a \"File not found\" error if this takes over a certain amount of time. rm must be running faster than exiftool can finish?<br \/>\n\t\t\t\tdisplay dialog \"The 'exiftool' command said: \" & theErr<br \/>\n\t\t\tend try<br \/>\n\t\t\tdelay 1<br \/>\n\t\t\ttry<br \/>\n\t\t\t\t-- Ready for this, exiftool adds \"_original\" to the end of the file it's going to modify tags\/atoms of. This is still 'newfile' but with a new name.<br \/>\n\t\t\t\t-- If we manually add \"_original\" to 'newfile' rm will throw an error looking for newfile_original_original... Wha?<br \/>\n\t\t\t\tdo shell script \"rm \" & quoted form of POSIX path of newfile<br \/>\n\t\t\ton error theErr<br \/>\n\t\t\t\tdisplay dialog \"The 'rm' command said: \" & theErr<br \/>\n\t\t\tend try<br \/>\n\t\t\tdelay 1<br \/>\n\t\t\ttry<br \/>\n\t\t\t\t-- Ready again? The original path to 'newfile' is valid again for this... Wha??<br \/>\n\t\t\t\tdo shell script \"setfile -d '\" & c_date & \"' -m '\" & m_date & \"' \" & quoted form of POSIX path of newfile<br \/>\n\t\t\ton error theErr<br \/>\n\t\t\t\tdisplay dialog \"The 'setfile' command said: \" & theErr<br \/>\n\t\t\tend try<br \/>\n\t\tend if<br \/>\n\t\texit repeat<br \/>\n\tend repeat<br \/>\n\tif redo then do_it(false)<br \/>\nend do_it<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the companion script for: Video re-encode script It uses exiftool to copy the video date atom(s) and setfile (is or was included with Apple&#8217;s Developer Tools) to change the file system dates. It will more than likely throw exiftool &#8220;File not found&#8221; errors and I&#8217;m not quite sure why. It has never failed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[10,24,28],"class_list":["post-777","post","type-post","status-publish","format-standard","hentry","category-code","tag-applescript-2","tag-macos","tag-os-x"],"_links":{"self":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts\/777","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/comments?post=777"}],"version-history":[{"count":0,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts\/777\/revisions"}],"wp:attachment":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/media?parent=777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/categories?post=777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/tags?post=777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}