How to loop csv file when running from command line/terminal?

I’m not good at scripting, how can I loop across a CSV file when running from command prompt/terminal?

Basically I want to achieve:

  1. Open chrome
  2. Read csv file1 line 1
  3. Do actions.
  4. Save results to csv file2 line 1
  5. Kill Chrome

I want to loop across the entire csv not run line 1 repeatedly. How can I do this?

I have seen maybe I need to send value via the &!cmd_var1=VALUE ?

I want to do this on MacOS ideally. I can run python if needed.

Thank you

There are several methods to create a loop with ui vision, the simplest method is to use the !TIMES command it works via command line

Thanks for the reply. This makes sense. However the issue is that I want to kill chrome after each loop and then reopen it and continue from the next line in the CSV. Any suggestion of how I might to do that?

You can use tab close command multiple times to close all tabs opened

Or you can simulate CTRL + W to close tab with Xtype

If you close browser you must save in csv the line number to continue the work in csv

Thanks. In macOS, CMD+w (same as CTRL+W) closes all the windows but doesn’t quit the application altogether as it stays running. So I would need to do CMD+Q to quit and then use python or my macOS script to reopen the application.

I guess I will need to store the line number of where I am in the csv in another csv file. Then the script should read the value pass that number to UI Vision/chrome on open so that the macro starts at the correct spot in the CSV. Is that basically the right way to do it?

You must save the number of the csv line already used to continue working with the next line the next time the browser is opened.
In Windows to close the browser you can also use ALT + F4 or other shortcut, I don’t know macOS

How do I do this? Ignore that it is macOS. I could save it in an external csv perhaps, but then how do I pass it back to the macro so it knows where to start the next time the browser is opened?

In my opinion it’s not a good idea to create an automation by continuously closing the browser, you risk many problems working this way.

My advice is to think well for at least 1 week about the work to be done, write the steps in the notepad, when you think it is the solution with the shortest code, write the code.

A short macro code is faster and easier to correct and I will have less risk of problems

To save the row number you need to use the csvsave command