Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

How to modify Automator Script (app) to rename MOV with date and time?

Here's my issue. First, I am thrilled to have found an Automator script written and posted by VikingOSX here:


Script to rename pictures with date and t… - Apple Community


....Which totally works... in renaming HEIC and JPEG images to their EXIF date and time data.


(I tried to reply there in the Community thread where the original functional script was posted, but that was not permitted.)


However, I also need to rename .MOV files too.


Now, VikingOSX's instructions were excellent. However, in order to get his automator script (app) to work, I had to do one more step. When VikingOSX wrote:


Then one drags and drops the following actions from their respective Library (in order) to the larger workflow window:
1. Files & Folders > Ask for Finder Items
2. Utilities > Run AppleScript


On that first one, I had to change the "Type" from "Files" to "Folders" as shown:


Before:


Choosing:


After:



Could someone, perhaps even @VikingOSX, advise me on how to revise the script to also rename .MOV files?


Here's the original script:


property imageKind : {"HEIF Image", "JPEG image"}
property app_icon : "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns"property imageCnt : (0 as integer)

on run {input, parameters}
	
	set parentdir to input
	set EXIFTOOL to (do shell script "PATH=\"/usr/local/bin:/opt/homebrew/bin:$PATH\";/usr/bin/which exiftool")
	
	tell application "Finder"
		set img_list to (every item in entire contents of folder parentdir whose kind is in imageKind) as alias list
		if img_list = {} then
			display alert "No images found"			return
		end if
		
		repeat with anImage in img_list
			set EXT to "." & anImage's name extension
			set DTO_string to (do shell script EXIFTOOL & " -s3 -d \"%F %H-%M-%S\" -DateTimeOriginal " & (POSIX path of anImage)'s quoted form)
			if not DTO_string = "" then
				set outFile to ((parentdir as text) & DTO_string & EXT) as text
				set basename to (do shell script "basename " & (outFile's quoted form)'s POSIX path)
				set name of anImage to basename
				set imageCnt to imageCnt + (1 as integer)
			else
				log "NO-OP"
			end if
		end repeat
		
	end tell
	
	display dialog "Processed image count:  " & (imageCnt as text) with title "Processing complete" with icon POSIX file app_icon as alias	
	returnend run

MacBook Pro 16″, macOS 13.6

Posted on Sep 29, 2023 5:49 PM

Reply
Question marked as Best reply

Posted on Sep 29, 2023 11:06 PM

OK, I solved it! :-)


For sniffing out how to word the "kind" property, in Mac Finder, I right-clicked on both .MOV and .MP4 files. for .MOV the kind is listed as "QuickTime movie" while for .MP4 the kind is listed as "MPEG-4 movie."



I then cloned the "batch loop" part of the code in the script so I could tailor a new loop for dealing just with the two video file kinds. I tweaked for adding PNG and then I created "video" styled copies of the various property vars and other vars. For example, where the original script had:


property imageKind : {"HEIF image", "JPEG image"}


I now have:


property imageKind : {"HEIF image", "JPEG image", "PNG image"}
property videoKind : {"QuickTime movie", "MPEG-4 movie"}


This not only adds PNG catching but allows catching the two video types, .MOV and .MP4.


Also, for having the ExifTool utility to "get at" the date and time of the video files, I sleuthed around, and found that I could get a glimpse of all that the tool could snag from a .MOV file with this command in terminal:


exiftool -G1 -a -s -Time:all /path/to/file.MOV


Which gives a whole list of values (see main part of screen shot below), and from that list, I honed in on "CreateDate" and ran this command in terminal:


exiftool -CreateDate /path/to/file.MOV


...which gives the desired info (see lowest part of screen shot below).



So based on that, where the original loop's crucial bit was:


set DTO_string to (do shell script EXIFTOOL & " -s3 -d \"%F %H-%M-%S\" -DateTimeOriginal " & (POSIX path of anImage)'s quoted form) 


...the new loop's crucial bit has:


set DTO_string to (do shell script EXIFTOOL & " -s3 -d \"%F %H-%M-%S\" -CreateDate " & (POSIX path of aVideo)'s quoted form)


And... THAT WORKS! YAHOO!


Here is my whole script:


property imageKind : {"HEIF image", "JPEG image", "PNG image"}
property videoKind : {"QuickTime movie", "MPEG-4 movie"}
property app_icon : "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns"
property imageCnt : (0 as integer)
property videoCnt : (0 as integer)

on run {input, parameters}
    
    set parentdir to input
    set EXIFTOOL to (do shell script "PATH=\"/usr/local/bin:/opt/homebrew/bin:$PATH\";/usr/bin/which exiftool")
    
    tell application "Finder"
        set img_list to (every item in entire contents of folder parentdir whose kind is in imageKind) as alias list
        set vid_list to (every item in entire contents of folder parentdir whose kind is in videoKind) as alias list

        if img_list = {} and vid_list = {} then
            display alert "No images or videos found"
            return
        end if

        repeat with anImage in img_list
            set EXT to "." & anImage's name extension
            set DTO_string to (do shell script EXIFTOOL & " -s3 -d \"%F %H-%M-%S\" -DateTimeOriginal " & (POSIX path of anImage)'s quoted form)
            if not DTO_string = "" then
                set outFile to ((parentdir as text) & DTO_string & " " & anImage's name) as text
                set basename to (do shell script "basename " & (outFile's quoted form)'s POSIX path)
                set name of anImage to basename
                set imageCnt to imageCnt + (1 as integer)
            else
                log "NO-OP"
            end if
        end repeat

        repeat with aVideo in vid_list
        set EXT to "." & aVideo's name extension
        set DTO_string to (do shell script EXIFTOOL & " -s3 -d \"%F %H-%M-%S\" -CreateDate " & (POSIX path of aVideo)'s quoted form)
        if not DTO_string = "" then
            set outFile to ((parentdir as text) & DTO_string & " " & aVideo's name) as text
            set basename to (do shell script "basename " & (outFile's quoted form)'s POSIX path)
            set name of aVideo to basename
            set videoCnt to videoCnt + (1 as integer)
        else
            log "NO-OP"
        end if
        end repeat
        
    end tell

    display dialog "Processed image count:  " & (imageCnt as text) with title "Image name processing complete" with icon POSIX file app_icon as alias
    
    display dialog "Processed video count:  " & (videoCnt as text) with title "Video name processing complete" with icon POSIX file app_icon as alias

    return
end run

Similar questions

2 replies
Question marked as Best reply

Sep 29, 2023 11:06 PM in response to DougGJoseph

OK, I solved it! :-)


For sniffing out how to word the "kind" property, in Mac Finder, I right-clicked on both .MOV and .MP4 files. for .MOV the kind is listed as "QuickTime movie" while for .MP4 the kind is listed as "MPEG-4 movie."



I then cloned the "batch loop" part of the code in the script so I could tailor a new loop for dealing just with the two video file kinds. I tweaked for adding PNG and then I created "video" styled copies of the various property vars and other vars. For example, where the original script had:


property imageKind : {"HEIF image", "JPEG image"}


I now have:


property imageKind : {"HEIF image", "JPEG image", "PNG image"}
property videoKind : {"QuickTime movie", "MPEG-4 movie"}


This not only adds PNG catching but allows catching the two video types, .MOV and .MP4.


Also, for having the ExifTool utility to "get at" the date and time of the video files, I sleuthed around, and found that I could get a glimpse of all that the tool could snag from a .MOV file with this command in terminal:


exiftool -G1 -a -s -Time:all /path/to/file.MOV


Which gives a whole list of values (see main part of screen shot below), and from that list, I honed in on "CreateDate" and ran this command in terminal:


exiftool -CreateDate /path/to/file.MOV


...which gives the desired info (see lowest part of screen shot below).



So based on that, where the original loop's crucial bit was:


set DTO_string to (do shell script EXIFTOOL & " -s3 -d \"%F %H-%M-%S\" -DateTimeOriginal " & (POSIX path of anImage)'s quoted form) 


...the new loop's crucial bit has:


set DTO_string to (do shell script EXIFTOOL & " -s3 -d \"%F %H-%M-%S\" -CreateDate " & (POSIX path of aVideo)'s quoted form)


And... THAT WORKS! YAHOO!


Here is my whole script:


property imageKind : {"HEIF image", "JPEG image", "PNG image"}
property videoKind : {"QuickTime movie", "MPEG-4 movie"}
property app_icon : "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns"
property imageCnt : (0 as integer)
property videoCnt : (0 as integer)

on run {input, parameters}
    
    set parentdir to input
    set EXIFTOOL to (do shell script "PATH=\"/usr/local/bin:/opt/homebrew/bin:$PATH\";/usr/bin/which exiftool")
    
    tell application "Finder"
        set img_list to (every item in entire contents of folder parentdir whose kind is in imageKind) as alias list
        set vid_list to (every item in entire contents of folder parentdir whose kind is in videoKind) as alias list

        if img_list = {} and vid_list = {} then
            display alert "No images or videos found"
            return
        end if

        repeat with anImage in img_list
            set EXT to "." & anImage's name extension
            set DTO_string to (do shell script EXIFTOOL & " -s3 -d \"%F %H-%M-%S\" -DateTimeOriginal " & (POSIX path of anImage)'s quoted form)
            if not DTO_string = "" then
                set outFile to ((parentdir as text) & DTO_string & " " & anImage's name) as text
                set basename to (do shell script "basename " & (outFile's quoted form)'s POSIX path)
                set name of anImage to basename
                set imageCnt to imageCnt + (1 as integer)
            else
                log "NO-OP"
            end if
        end repeat

        repeat with aVideo in vid_list
        set EXT to "." & aVideo's name extension
        set DTO_string to (do shell script EXIFTOOL & " -s3 -d \"%F %H-%M-%S\" -CreateDate " & (POSIX path of aVideo)'s quoted form)
        if not DTO_string = "" then
            set outFile to ((parentdir as text) & DTO_string & " " & aVideo's name) as text
            set basename to (do shell script "basename " & (outFile's quoted form)'s POSIX path)
            set name of aVideo to basename
            set videoCnt to videoCnt + (1 as integer)
        else
            log "NO-OP"
        end if
        end repeat
        
    end tell

    display dialog "Processed image count:  " & (imageCnt as text) with title "Image name processing complete" with icon POSIX file app_icon as alias
    
    display dialog "Processed video count:  " & (videoCnt as text) with title "Video name processing complete" with icon POSIX file app_icon as alias

    return
end run

Sep 30, 2023 6:57 AM in response to DougGJoseph

Good sleuthing. 😎


You can shorten the following:


set EXIFTOOL to (do shell script "PATH=\"/usr/local/bin:/opt/homebrew/bin:$PATH\";/usr/bin/which exiftool")


to


set EXIFTOOL to (do shell script "source ~/.dotfile;exiftool")


where that .dotfile is the name of where your export PATH=" " string is located for your given SHELL. It might be .bashrc, .bash_profile, or even .zshrc. Assumption is that you have already set the desired PATH in your SHELL's dotfile.


Unless you used the original ExifTool installer from its site which installs exiftool into /usr/local/bin, the use of homebrew will place it in the same location on Intel Macs and in /opt/homebrew/bin on Apple Silicon Macs.


How to modify Automator Script (app) to rename MOV with date and time?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.