Automator QA works on one file. Can I make it work on several files?

Hi, I am using Automator to extract 3 blocks of text (from a .txt file), using AppleScript it combines the text and displays it in a Dialog Box. I then manually copy the contents of the Dialog and paste it into Notepad. Although a bit clunky, this is working ok but I really would like it to loop through several files at once (between 1 & 10). The resulting text may be too long to fit in a dialog box, so perhaps it could all be combined and saved to a variable (or the clipboard?) for later use?

Currently, I select the appropriate file in finder and right click to run the Quick Action.

Any help would be appreciated. Thanks.

“The Workflow Receives Current [Files or Folders] in [Finder]”


on run {input, parameters}
	
	set theFile to input
	set theFileContents to read theFile as text	
	
	set AddressStartPosition to offset of "Random Company Ltd" in theFileContents
	
	set AddressEndPosition to offset of "Hampshire" in theFileContents
	
	set FirstPosition to offset of "1.31 Comments" in theFileContents
	
	set SecondPosition to offset of "1.32 Recommendations" in theFileContents
	
	set ThirdPosition to offset of "3.31 Comments" in theFileContents
	
	set ForthPosition to offset of "3.32 Recommendations" in theFileContents
	
	set Address to (characters (AddressStartPosition + 28) thru (AddressEndPosition - 1) of theFileContents) as string
	set FirstPageComments to (characters FirstPosition thru (SecondPosition - 1) of theFileContents) as string
	set ThirdPageComments to (characters ThirdPosition thru (ForthPosition - 1) of theFileContents) as string
	
	set FullText to Address & FirstPageComments & ThirdPageComments
	
	display dialog FullText
	return input
end run

Made it work! I have taken it out of Automator and just run it as a script now. Still clunky but does what I want.:slight_smile:


tell application "Finder"
	
	set TempFileContents to ""
	set NumberOfFiles to (count of (selection as alias list))
	set ItemNumber to 1
	
	repeat NumberOfFiles times
		
		set theFile to item (ItemNumber) of (get selection)
		set fileRef to open for access (theFile as alias)
		set thefileContents to (read fileRef)
		close access fileRef
		
		set AddressStartPosition to offset of "Random Company Ltd" in thefileContents
		set AddressEndPosition to offset of "Hampshire" in thefileContents
		set FirstPosition to offset of "1.31 Comments" in thefileContents
		set SecondPosition to offset of "1.32 Recommendations" in thefileContents
		set ThirdPosition to offset of "3.31 Comments" in thefileContents
		set ForthPosition to offset of "3.32 Recommendations" in thefileContents
		set Address to (characters (AddressStartPosition + 28) thru (AddressEndPosition - 1) of thefileContents) as string
		set FirstPageComments to (characters FirstPosition thru (SecondPosition - 1) of thefileContents) as string
		set ThirdPageComments to (characters ThirdPosition thru (ForthPosition - 1) of thefileContents) as string
		
		set FullText to Address & FirstPageComments & ThirdPageComments
		
		set ItemNumber to ItemNumber + 1
		
		set TempFileContents to TempFileContents & FullText
	end repeat
	
end tell

set the clipboard to TempFileContents

display dialog "Comments from " & ItemNumber - 1 & " files have been added to the clipboard."