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

Automator - Loop through a text file and process data through a 3rd party software

Just stumbled on Automator the other day (I am a mac n00b) and would like to automate the processing of a text file, line-by-line, using a third party tool. I would like Automator to loop through the text file one line at a time, copy the string and keep as a variable. Next, place the variable data (copied string) into the text field of the 3rd party software for processing. Once the processing is complete, I would like Automator to fetch the next line/string for processing. I see items like "copy from clipboard" and "variables" within the menu but I am not finding much documentation on how to utilizle this tool. Just hear how potentially powerful it is.


The 3rd party software is not a brand name, just something made for me to process text. I may have to use mouse clicks or tabs + [return] to navigate with Automator. A term I heard on Bn Walldie's itunes video series was "scriptable software" for which I don't think this 3rd party app would be.


Kind regards,


jw

Automator-OTHER, Mac OS X (10.7.2)

Posted on Jan 23, 2012 12:39 PM

Reply
Question marked as Best reply

Posted on Jan 23, 2012 10:27 PM

Good news and bad news...


The good news is that it should be entirely possible to automate your workflow.


The bad news is that it will be a nightmare to implement via Automator, if it's even possible.


Automator is, essentially a pretty interface on top of AppleScript/Apple Events, and with the pretty interface comes a certain stranglehold on features. Knowing how to boil rice might make you a cook, but understanding flavor profiles and ingredient combinations can make you a chef, and it's the same with AppleScript and Automator. Automator's good at getting you from points A to B but if there are any bumps in the road (e.g. the application you're using isn't scriptable) then it falls apart.


What I'm getting at is that your requirements are pretty simple to implement in AppleScript because you can get 'under the hood' and do exactly what you want, as opposed to Automator's restricted interface.


The tricky part is that if no one else can see this app it's going to be hard to tell you what to do.


I can give you the basics on reading a file and iterating through the lines of text in it, and I can show you how to 'type' text in any given application, but it may be up to you to put the pieces together.


Here's one way of reading a file and working through each line of text:


-- ask the user for a file:

set theFile to (choose file)

-- read the file contents:

set theFileContents to (readfiletheFile)

-- break out the lines/paragraphs of text:

set theLines to paragraphs of theFileContents


-- now iterate through those lines, one by one:

repeat with eachLine in theLines


-- code to perform for eachLine goes here

end repeat

Once you have a line of text (eachLine in the above example) you can 'type' that into another application via something like:


tell application "AppName" to activate

tell application "System Events"

tell process "AppName"


keystrokeeachLine

end tell

end tell


Here the AppleScript is activating the application and using System Events to emulate typing the contents of the eachLine variable into the process. Put this inside your repeat loop and you're almost there.

2 replies
Question marked as Best reply

Jan 23, 2012 10:27 PM in response to jasonewillis

Good news and bad news...


The good news is that it should be entirely possible to automate your workflow.


The bad news is that it will be a nightmare to implement via Automator, if it's even possible.


Automator is, essentially a pretty interface on top of AppleScript/Apple Events, and with the pretty interface comes a certain stranglehold on features. Knowing how to boil rice might make you a cook, but understanding flavor profiles and ingredient combinations can make you a chef, and it's the same with AppleScript and Automator. Automator's good at getting you from points A to B but if there are any bumps in the road (e.g. the application you're using isn't scriptable) then it falls apart.


What I'm getting at is that your requirements are pretty simple to implement in AppleScript because you can get 'under the hood' and do exactly what you want, as opposed to Automator's restricted interface.


The tricky part is that if no one else can see this app it's going to be hard to tell you what to do.


I can give you the basics on reading a file and iterating through the lines of text in it, and I can show you how to 'type' text in any given application, but it may be up to you to put the pieces together.


Here's one way of reading a file and working through each line of text:


-- ask the user for a file:

set theFile to (choose file)

-- read the file contents:

set theFileContents to (readfiletheFile)

-- break out the lines/paragraphs of text:

set theLines to paragraphs of theFileContents


-- now iterate through those lines, one by one:

repeat with eachLine in theLines


-- code to perform for eachLine goes here

end repeat

Once you have a line of text (eachLine in the above example) you can 'type' that into another application via something like:


tell application "AppName" to activate

tell application "System Events"

tell process "AppName"


keystrokeeachLine

end tell

end tell


Here the AppleScript is activating the application and using System Events to emulate typing the contents of the eachLine variable into the process. Put this inside your repeat loop and you're almost there.

Mar 28, 2013 12:15 PM in response to Camelot

Hi there,


I am trying to build automator wrkflw which would take a txt file, loop through line by line and use each line to make new reminder in reminders app. When input to Make new Reminder action is text reminders look good but I cant get it to loop through file nor to make more than one reminder, which is not odd considering that I came accross applescript few hours ago.

I would really appreciate any help, it looks like a piece of cake for an experienced dude.


Thanks in advance!!!

Best regards from Croatia,


m

Automator - Loop through a text file and process data through a 3rd party software

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