Automator memory leak workaround for multi-file processing

I encountered an issue similar to the one described here: Automator Lag - Apple Community.


I restructured my Automator workflow in a way that I believe avoids a possible memory leak. The workaround is to call an embedded workflow which processes a single file from loop implemented in AppleScript (see example below).


- Pie Lover


AppleScript multi-file loop

on run {input, parameters}

set workflowpath to "/Users/admin/Pictures/Apply sRGB Profile to Images.workflow"
set qtdworkflowpath to quoted form of (POSIX path of workflowpath)

set theseImageFiles to input

repeat with i from 1 to the count of theseImageFiles
set thisImageFile to item i of theseImageFiles
set qtdthisImageFile to quoted form of (POSIX path of thisImageFile)
set command to "/usr/bin/automator -i " & qtdthisImageFile & " " & qtdworkflowpath
set output to do shell script command

end repeat

end run


[Re-Titled by Moderator]




Mac mini (2018)

Posted on Jan 4, 2025 5:16 PM

Reply
2 replies
Sort By: 

Jan 5, 2025 6:54 AM in response to BlueberryLover

Below is a slightly modified version which avoids specifying the username in the workflow path.


- Pie Lover



Make use of shell expansion of "~"

on run {input, parameters}
	
	set workflowpath to do shell script "echo ~/Pictures/Apply sRGB Profile to Images.workflow"
	set qtdworkflowpath to quoted form of (POSIX path of workflowpath)
	
	set theseImageFiles to input
	
	repeat with i from 1 to the count of theseImageFiles
		set thisImageFile to item i of theseImageFiles
		set qtdthisImageFile to quoted form of (POSIX path of thisImageFile)
		set command to "/usr/bin/automator -i " & qtdthisImageFile & " " & qtdworkflowpath
		set output to do shell script command
		
	end repeat
	
end run

Reply

Jan 6, 2025 6:15 AM in response to BlueberryLover

A slightly more compact version ...


on run {input, parameters}
	
	set workflowpath to do shell script "echo ~/Pictures/Apply sRGB Profile to Images.workflow"
	set qtdworkflowpath to quoted form of (POSIX path of workflowpath)
	
	repeat with thisImageFile in input
		set qtdthisImageFile to quoted form of (POSIX path of thisImageFile)
		set command to "/usr/bin/automator -i " & qtdthisImageFile & " " & qtdworkflowpath
		set output to do shell script command
	end repeat
	
end run

Reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Automator memory leak workaround for multi-file processing

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