Adding spotlight comments

OK - new to this but having been spending much time reading and looking for examples ect.

This is the goal:
I want to take the first line of a document and copy it and then add it to the spotlight comment section in the get info window.
I need to process about 400+ documents in this manner.
I have a script that works . . . but it is written to a specific file.
Here it is:


tell application "Microsoft Word"
	activate
	set newComment to text of first line of document 1
	close window 1
end tell

tell application "Finder"
	set comment of document file "2005JJXPDQJA.dot" of folder "Run script folder" of folder "Desktop" of folder "wadsmd" of folder "Users" of startup disk to newComment
end tell

As you can see - this only works for the file “2005JJXPDQJA.dot”. I need to change the second part of the script.
I would like to be able to drop a file in the Run script folder - have it run the script and then so forth.
I can’t figure out how to abstract the “set comment . .” to apply to any file in that folder.

thanks in advance for any help.

Model: MacBook Pro
AppleScript: AppleScript 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi wads,

I’m not sure I really understand the "…drop a file in the Run script folder ", but here are a couple of suggestions

  1. This will add comments to every document file in the chosen folder.

global newComment
tell application "Finder" to try
	set fileList to every document file of (choose folder) whose creator type is {"MSWD"}
	
	repeat with aFile in fileList
		
		tell application "Microsoft Word"
			open aFile
			--  set newComment to text of first line of document 1 --> does NOT work for me on Word 2004
			set newComment to content of text object of first paragraph of document 1
			set newComment to (text items 1 thru -2 of newComment) as text
			close window 1
		end tell
		
		set c to comment of aFile
		if c is "" then
			set comment of aFile to newComment
		else
			set comment of aFile to c & return & newComment
		end if
		
	end repeat
end try

  1. This is a Folder Action. Attach it to a folder and drop the docs you want to comment onto.

on adding folder items to _folder after receiving _items
	try
		repeat with aFile in _items
			
			tell application "Microsoft Word"
				open aFile
				set newComment to content of text object of first paragraph of document 1
				set newComment to (text items 1 thru -2 of newComment) as text
				close window 1
			end tell
			
			tell application "Finder"
				set c to comment of aFile
				if c is "" then
					set comment of aFile to newComment
				else
					set comment of aFile to c & return & newComment
				end if
			end tell
			
		end repeat
	end try
end adding folder items to

I hope it helps

Yannis A.

It’s sounds like Yannis is on track. I’m not sure if this is helps the current situation, but it’s worth mentioning: Set Finder/Spotlight Comments

Hey - thanks guys - that worked perfectly. This forum/site is so awesome - I’ve gone from knowing
nothing about applescript - to being able to read/write scripts. I’m still learning though . . thanks!

I did have to keep the line:
set newComment to text of first line of document 1

rather than:
set newComment to content of text object of first paragraph of document 1
set newComment to (text items 1 thru -2 of newComment) as text

I am using MS Word X Service Release 1
I assume the differences are due to the versions.

One more question:
Is there a way to also add the same information to the properties section (under title) of the MS word document?
Go File->Properties and get the window - I would like to add the same info to the Title section.
This would allow for sorting of files under Mac and Windows

Model: MacBook Pro
AppleScript: AppleScript 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hello

Third version: a droplet.

Save the script as an application.

Drag and drop the folder containing the docs onto the script’s icon.

global newComment

set _ to (choose folder)

open {_}
on open (sel)
	set aFolder to sel's item 1
	tell application "Finder" to try
		set fileList to every document file of aFolder whose creator type is {"MSWD"}
		
		repeat with aFile in fileList
			
			tell application "Microsoft Word"
				open aFile
				--  set newComment to text of first line of document 1 --> does NOT work for me on Word 2004
				set newComment to content of text object of first paragraph of document 1
				set newComment to (text items 1 thru -2 of newComment) as text
				close window 1
			end tell
			
			set newComment to (current date) as text
			set c to comment of aFile
			if c is "" then
				set comment of aFile to newComment
			else
				set comment of aFile to c & return & newComment
			end if
			
		end repeat
	end try
end open

Yvan KOENIG (from FRANCE vendredi 29 septembre 2006 19:06:19)

On Word 2004 that should be


--- insert next line where appropriate
set value of document property "Title" of document 1 to newComment
-- rest of the code

… as I don’t have access to Word X, I can’t verify it works for you too. But it wouldn’t be that much different. Browse the dictionary in Script Editor and check the properties of the document property class for the correct syntax.

Good luck
Yannis

Ps. Thanks the ‘point outs’ guys :slight_smile:

Thanks for your help! I’ll try it out

Model: MacBook Pro
AppleScript: AppleScript 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)