I did some experimenting and this setup works pretty well.
First you need to collect all your files in a specific folder.
That folder must have comments visible. (Right-click the folder, select View Options, check "Comments")
Next, you'll need to save this script in your /Library/Scripts/Folder Action Scripts/ folder.
Here's the script:
Code:
on adding folder items to this_folder after receiving added_items
tell application "Finder"
set fold_name to the name of this_folder
try
repeat with i from 1 to number of items in added_items
set new_item to item i of added_items
if name extension of new_item is "pages" then
tell application "Pages"
open new_item
set wc to the count of words of document 1
close document 1
end tell
if wc > 0 then
set comment of new_item to "Word count: " & (wc as string) & return
end if
end if
-- display dialog "Added: 'Word count: " & wc & "'"
end repeat
on error errMsg number errNum
display dialog errMsg & return & "Error: " & (errNum as string)
end try
end tell
end adding folder items to
on opening folder this_folder
tell application "Finder"
set fold_name to the name of this_folder
try
set all_items to items of this_folder
repeat with i from 1 to count of all_items
set new_item to item i of all_items
if name extension of new_item is "pages" then
tell application "Pages"
open new_item
set wc to the count of words of document 1
close document 1
end tell
if wc > 0 then
set comment of new_item to "Word count: " & (wc as string) & return
end if
end if
-- display dialog "Added: 'Word count: " & wc & "'"
end repeat
on error errMsg number errNum
display dialog errMsg & return & "Error: " & (errNum as string)
end try
end tell
end opening folder
After you've saved the script, you'll need to configure the folder to accept folder actions. Right-click the folder and the pop-up menu should include "Folder Actions Setup..." Window should pop up, then a panel should slide from the title bar. If you've saved the script in the right folder, it should appear and just select it. Then quit the Folder Actions Setup app.
I used Pages as the word processor. If you're using Word, I'm sure the syntax is similar.
Basically, if you copy a file into your work folder, the script opens it, gets the word count, then closes it. It then sets the Spotlight comment to "Word count: xxx"
The second half of the script is an easy way to update the word count after you've edited a file. Folder Actions don't seem to recognize when a file has changed. If you've edited a file, just close and open the folder and the script will run through all the files. If you've got a lot, it might be painful; maybe there's an alternative. But if you only have a few, this script runs pretty quick.
mt