Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Getting File Comments

Getting File Comments
Thread Tools
Fresh-Faced Recruit
Join Date: Jan 2001
Location: toronto, ontario, canada
Status: Offline
Reply With Quote
Feb 8, 2001, 03:42 PM
 
HELP!

I am an AppleScript beginner. I'm looking for a way to generate a text list of File Comments. Ultimately I would like to be able to drop multiple files/folders onto an AppleScript which will 'spit out' the File Comments when they exist in text format (SimpleText/Word).

This code is from AppleScript's Help:

on open this_item
tell application "Finder"
activate
set the item_comments to the comment of this_item
if the item_comments is "" then set the item_comments ¬
to "This item has no comment."
display dialog the item_comments
end tell
end open


I saved this script as a Classic Applet, then dropped a various items (with comments) onto it. It seems that the script is faulty or I'm not getting something. I get this error:
Can't get comment of {alias "QUINCY:incoming OEM list_202"}

Frustrated & desperate,
jyiu
production@boatshow.com
     
Dedicated MacNNer
Join Date: Nov 1999
Location: Georgetown, Demerara, Guyana
Status: Offline
Reply With Quote
Feb 9, 2001, 12:19 AM
 
Hi jyiu,

I agree that this quirky behaviour of the scriptable Finder can be quite frustrating... The underlying problem is that your droplet's 'open' handler is actually being supplied with a list of item references rather than just a single item reference, contrary to what is being implied by the singular 'this_item' variable name. (If you drag only one item onto your droplet, the list would contain exactly one item reference.)

Assuming that you're using a recent version of the Finder (Mac OS 8.5.x+), you could modify the fourth line of the script so that the Finder operates on the single item reference itself (as opposed to the enclosing list). So, the modified code might look something like this (with the changes highlighted in bold on line 4):-
Code:
on open this_item tell application "Finder" activate set the item_comments to the comment of (item 1 of this_item) if the item_comments is "" then set the item_comments ¬ to "This item has no comment." display dialog the item_comments end tell end open
A somewhat related problem is that older versions of the Finder (Mac OS 8.1-) seem to consistently work with only one kind of item reference form, viz., the so-called "Finder (or Object) Reference Form" [e.g., 'item "itemName" of folder "folderName" ... of disk "diskName"']. Unfortunately, some older Finders tend not to consistently work with other standard kinds of reference forms such as the "Name (or Path) Reference Form" [e.g., '"diskName:folderName:...:itemName"'], or the "Alias Reference Form" [e.g., '(alias "diskName:folderName:...:itemName")']. Although, in certain cases, the older Finders do seem to be able to use these other kinds of reference forms, particularly the Alias Reference Form.

[For further details on the various reference forms, please refer to the following sources:- the 'Automating Tasks' -> Automating tasks in the Finder' -> 'Referring to items in the Finder' subsection (just above the 'Getting and setting comments' subsection from where you obtained the "get comments" sample script) of the AppleScript Help section of the Help Center; the official Apple documentation available on the AppleScript for Scripters web page (especially Chapter 5, "Objects and References", of the AppleScript Language Guide, and Chapter 2, "Finder Objects", of the AppleScript Finder Guide); and, the third-party AppleScript SourceBook's Dereferencing File References web page.]

Anyway, to make a long story short, if you're using an older version of the Finder, you might also need to modify the fourth line of the script so that the Finder gets to operate on the extracted item in its preferred Finder Reference Form. One way to do this would be to first coerce the extracted Alias Reference Form [i.e., '(item 1 of this_item)'] into a Name Reference Form [i.e., '((item 1 of this_item) as text)'], and then finally to coerce that Name Reference Form into a Finder Refernce Form [i.e., '(item ((item 1 of this_item) as text))']. So, the further modified code might look something like this (with the additional changes highlighted in bold on line 4):-
Code:
on open this_item tell application "Finder" activate set the item_comments to the comment of (item ((item 1 of this_item) as text)) if the item_comments is "" then set the item_comments ¬ to "This item has no comment." display dialog the item_comments end tell end open
[For additional examples of processing Finder comments, including the use of a repeat loop to process the entire list of dragged items (when more than one item is dragged), see the earlier related threads in this Forum -- e.g., the accessing file comments (e.g. in get info) thread, the Script to delete comments in files? thread and the Batch Commenting Files. thread.]

Regards,

--Paul

[This message has been edited by Paul Crawford (edited 02-09-2001).]
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:09 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2