Reply to topic  [ 5 posts ] 
Remove Keywords 
Author Message

Joined: 2007-11-09 15:27:25
Posts: 86
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?
Thanks


2009-10-25 06:25:37
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
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.
Code:
$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

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.


2009-10-26 15:47:09
Profile WWW

Joined: 2007-11-09 15:27:25
Posts: 86
I'm glad you can say it's not too hard, because it looks like quite a bit of work.

Thank you very much, Martin.

This will make the job much easier.


2009-10-26 16:51:39
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
No problem. I hope your universe brightens up soon!


2009-10-26 17:43:38
Profile WWW
User avatar

Joined: 2005-12-11 06:45:07
Posts: 12
Location: Munich, Germany
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!

_________________
Thomas B.


2009-12-28 00:38:44
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software