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).]