Get help using and writing Nisus Writer Pro macros.
5 posts • Page 1 of 1
A demon entered while I was asleep and added several keywords to about 400 rtf files. Keywords as in Finder keywords. Of course I want to get rid of these, since they reflect a dark and strange view of the universe. These keywords are editable via File > Properties, of course. How difficult would it be to write a macro to perform a batch operation to remove keywords?
- Official Nisus Person
- Posts: 4261
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
The macro isn't too hard, but it's not terribly efficient. It works by opening up each file in a NWP window, altering the keywords, and then resaving the whole file back out. It operates on all files in a single folder you select at the start, but doesn't descend into subfolders.
The line that starts "$doc.setProperty" changes the keybwords to the empty string, which clears the property. Let me know if you have any questions.
Code: Select all
$fileExts = Array.new('rtf', 'zrtf') # which file types to process # ask user what folder to batch process $folderPath = Choose Folder If ! $folderPath # user cancelled Exit End # collect all files of the proper type $fileNames = File.namesInFolderAtPath($folderPath) $filePaths = Array.new ForEach $name in $fileNames $ext = $name.filePathExtension If -1 != $fileExts.indexOfValue($ext) $path = $folderPath.filePathByAppendingComponent($name) $isFolder = File.isFolderAtPath($path) If ! $isFolder $filePaths.appendValue($path) End End End # make sure the user knows how many files will be processed $fileCount = $filePaths.count If 0 == $fileCount Exit 'No files of the correct type found in that folder.' End $choice = Prompt "Are you sure you want to process $fileCount files?", '', 'Process', 'Cancel' If 'Process' != $choice Exit End # process file ForEach $filePath in $filePaths Open $filePath $doc = Document.active $doc.setProperty('keywords', '') Save $doc.close End
Thanks Martin for the macro. I used it to make it work the other way round (inserting a keyword). Now the doc manager finds the required docs via smart filter. I replaced the empty ' ' with '[keyword]' -- and there you are. Thanks a lot!