Automator - Can Someone Make This Work?

I have a script that I’m trying to get working in Automator. What I want to do is input a text file, run this script and it out put a new text file based on the changes the script was to do. I can get this to run perfectly in Terminal but not anywhere else. See script below:

If it needs to go into Applescript, that is completely fine to. Right now, I can only do it through terminal but I want to automate the process for others.


To me it seems like your script is reading standard input. Please post the whole thing, (As you have implemented it so far in a Automator action, with parameters, and describe what it is supposed to do, that will make it easier to help you.



So I open Automator, I just save a new file as a workflow right now. Then this is what I start setting for the workflow:

  1. Get Specified Finder Items (I select my text document here)
  2. Run Shell Script:

What this script is suppose to do is add custom text (eg Faux_Folder/) to every single line at the 32 character mark.

EG: Original text file is: 12345678912345678912345678912345/Testing/Testing
New Text file will be: 12345678912345678912345678912345 Faux_Folder/Testing/Testing

Now, I get this to work in Terminal perfectly, just can’t get it to work in Automator at all. Would be nice to avoid using Terminal since a lot of my colleagues are not comfortable with using it.


I’ll come back with a much better an generic way to do this. In this post. (It’s kinda late in Norway right now.)

Totally ok! :slight_smile:

Any help is much appreciated!

Hello. I have created an Applescript Action for you, that is to be run from a Service/Workflow, and takes a selected file from the frontmost Finder window as its input.

it doesn’t look like much that you presented to me, but that is because the filenames are then delimited by “:” and not “/” since the filename are represented in the hfs-format.

There is plenty with dialogs, and log statements, that shows you intermediate results of the conversion, if something is wrong, or there is something you want to ask about, then just ask!

on run {input, parameters}
	log input
	set filename to input as text
	tell (a reference to AppleScript's text item delimiters)
		set {oldtids, contents} to {contents, ":"}
		set filename to text items -3 thru -1 of filename as text
		set contents to oldtids
	end tell
	log "-Z" & filename
	set d to length of filename
	tell current application
		display dialog filename
	end tell
	if length of filename > 32 then
		set a to text 1 thru 31 of filename
		set b to text 33 thru -1 of filename
		set c to a & " Faux Folder" & b
	end if
	tell current application
		display dialog c
	end tell
	(* Your script goes here *)
	set input to filename
	return input
end run

my apologies. I just re-read my post and that I said “Text File” when I should have have “Text IN File”.

The script I posted above changes the Text within a text file, not just the name of the file. Basically, my text file will have several lines of text that I will need to add text to each line. Example Below:

and I would like it to add text now at the 34th character while keeping all the text. Example Below:

Colleague changed some things around so here is now the updated script. It is still the same, just the character points have changed.


Ok, so I made a new service, that took text from a program (selected text). I checked off the the “Replaces selected” text option. I added a shell script action, which I let the standard Send selected text to stdin or whatever option be there.

I added a conversion of returns into linefeeds in your script, and now it works, when it is run, it replaces the selected text with the new one. I wouldn’t think of creating new text files from within a Service. Then you’d rather use AppleScript, and a dedicated program as context for selecting the lines.

Well, here is your shell script:


Only unfortunate thing is that we need to change the custom text each time we use it so a service won’t work. Unless it prompts a text field to input custom text? (eg Faux_Folder)

You’ll figure something out.