Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automator question

I would like to perform a simple task on all files in a folder. These are image files.

I would like to select a file in a folder, open Get Info (command-I), select and copy the file name from the Name & Extension field, and then paste it into the Comments field. Close Get Info, then select the next file in the folder and repeat until all files in the folder have been processed.


Can someone help me to do this? I'm not even sure where to start.


Thanks,

Marilyn

MacBook Pro 13″, macOS 10.12

Posted on May 9, 2021 4:20 PM

Reply
Question marked as Best reply

Posted on May 10, 2021 4:18 AM

I have a working Automator Application that prompts you for a folder containing your images. It then writes (or appends) the non-duplicate filename into the comments field of every image in that folder. It does not presently process sub-folders in that initial directory.


This Automator solution requires two actions:

  1. Files & Folders Library > Ask for Finder Items
    1. Start at: Desktop
    2. Type: Folders without Allow Multiple Section
  2. Utilities > Run AppleScript
    1. Remove all default content that appears in the added Run AppleScript action
    2. Replace with the code below that you copy/paste into the Run AppleScript action
      1. Click the hammer icon in the Run AppleScript action to compile that AppleScript
  3. You can click the Run ▸ button on the Automator application to test it before you save it on your Desktop
  4. Quit Automator


Run AppleScript Replacement Code


use scripting additions

property IMG : {"public.image"}

on run {input, parameters}
	
	set imgDir to (item 1 of input) as text
	
	tell application "Finder"
		set imgList to (every item of folder imgDir whose kind contains "image") as alias list
		
		if imgList is {} then return
		
		repeat with anImg in imgList
			set cmt to anImg's comment
			if cmt is "" then
				set anImg's comment to name of anImg
			else if cmt is equal to name of anImg then
				log "duplicate comment"
			else
				set anImg's comment to cmt & return & name of anImg
			end if
		end repeat
	end tell
	return
end run




Similar questions

8 replies
Question marked as Best reply

May 10, 2021 4:18 AM in response to oidsmom

I have a working Automator Application that prompts you for a folder containing your images. It then writes (or appends) the non-duplicate filename into the comments field of every image in that folder. It does not presently process sub-folders in that initial directory.


This Automator solution requires two actions:

  1. Files & Folders Library > Ask for Finder Items
    1. Start at: Desktop
    2. Type: Folders without Allow Multiple Section
  2. Utilities > Run AppleScript
    1. Remove all default content that appears in the added Run AppleScript action
    2. Replace with the code below that you copy/paste into the Run AppleScript action
      1. Click the hammer icon in the Run AppleScript action to compile that AppleScript
  3. You can click the Run ▸ button on the Automator application to test it before you save it on your Desktop
  4. Quit Automator


Run AppleScript Replacement Code


use scripting additions

property IMG : {"public.image"}

on run {input, parameters}
	
	set imgDir to (item 1 of input) as text
	
	tell application "Finder"
		set imgList to (every item of folder imgDir whose kind contains "image") as alias list
		
		if imgList is {} then return
		
		repeat with anImg in imgList
			set cmt to anImg's comment
			if cmt is "" then
				set anImg's comment to name of anImg
			else if cmt is equal to name of anImg then
				log "duplicate comment"
			else
				set anImg's comment to cmt & return & name of anImg
			end if
		end repeat
	end tell
	return
end run




May 10, 2021 1:21 PM in response to oidsmom

Also, I edited the script to :

set imgList to (every item of folder imgDir whose kind contains "JPEG image") as alias list


got a different message,


but it does work as long as I select the folder.

I just looked up ways to run an Automator workflow outside of Automator, I will try to doing that.


Again thanks so very much for your help on getting me started!

I need to get up to speed on Automator and refresh my AppleScript chops!


May 10, 2021 1:26 PM in response to oidsmom

I provided the code that you would save in an Automator Application, not Folder action.


From the Automator File menu, choose Convert To and select Application, then choose. Save that application to your Desktop as Image_comment, or whatever name you choose. Then you double-click that Automator application on the Desktop and it will prompt you for a folder and do its thing with comments on images.

Automator question

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