batch process a list of files

Get help using and writing Nisus Writer Pro macros.
Post Reply
Nobumi Iyanaga
Posts: 162
Joined: 2007-01-17 05:46:17
Location: Tokyo, Japan
Contact:

batch process a list of files

Post by Nobumi Iyanaga »

Hello,

Given that I have a list of file paths in the clipboard, such as this:

"/Users/[me]/Documents/NWP_backups/file1.rtf"
"/Users/[me]/Documents/NWP_backups/file2.rtf"
"/Users/[me]/Documents/NWP_backups/file3.rtf"

(delimited by returns), how would I open each of these files, make some change (I already have a macro which does the job), and close it?

Thank you very much in advance for any insights.
Best regards,

Nobumi Iyanaga
Tokyo,
Japan
User avatar
phspaelti
Posts: 1361
Joined: 2007-02-07 00:58:12
Location: Japan

Re: batch process a list of files

Post by phspaelti »

Hello Nobumi,
Not sure why you are starting with the file paths on the clipboard. But taking that at face value.
And what's with the quotations around the file paths strings? They would need to be removed.

So here's some code for a start:

Code: Select all

$filePathsText = Read Clipboard
$filePathsText.findAndReplace '"', '', 'a'
$filePaths = $filePathsText.split("\n")
foreach $filePath in $filePaths
  $doc = Open $filePath
  MyMacro # Replace this with the menu name of the macro
  Save
  $doc.close 
end
philip
Nobumi Iyanaga
Posts: 162
Joined: 2007-01-17 05:46:17
Location: Tokyo, Japan
Contact:

Re: batch process a list of files

Post by Nobumi Iyanaga »

Hello Philip,

Thank you very much, as always, for your macro model. I think I will be able to write my macro on this model.

I would start with the file paths on the clipboard, because I want to process a bunch of files that I will have selected on the Finder. What I actually want to do is to "textfy" NWP's rtf files that are stored in my backup folder. It may be possible to do that in one operation, but this would take too much time and power (I have more than 6000 files in my backup folder...!). I could make an AppleScript script to get the file paths of several files selected on the Finder, and put them in the clipboard. So, I may begin to work just after I have recorded these paths on the clipboard. This is because I am beginning to try to use Elephas, a new brand of AI based "knowledge database". To use it in a useful way, it is recommended to store data in its database, but it cannot read rtf files.

For the double quotes, I can easily remove them in the AppleScript script.

If I have more problems, I will ask here.

Thank you again!
Best regards,

Nobumi Iyanaga
Tokyo,
Japan
Post Reply