• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Writing Spotlight comments
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Writing Spotlight comments


  • Subject: Re: Writing Spotlight comments
  • From: Pierre Bernard <email@hidden>
  • Date: Mon, 12 Feb 2007 16:01:15 +0100

Thanks a bunch John!

Pierre


On 12 Feb 2007, at 14:43, John Pannell wrote:

Hi Pierre-

I have been using AppleScript to write to the Finder's "Spotlight Comments" field of files on disk. The AppleScript itself looks like this:

on SetSpotlightComment(pathToFile, newComment)
	tell application "Finder"
		set p to pathToFile as POSIX file
		set comment of p to newComment
	end tell
end SetSpotlightComment

The script must be stored somewhere as an NSAppleScript object to call, the url below is the location on disk (I kept it in my app bundle)...

_commentScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];

The setup to run the script in Cocoa is a mess, and I cobbled it together from things I found on the web:

// write spotlight comment
NSDictionary *errors = [NSDictionary dictionary];
NSAppleEventDescriptor *firstParameter = [NSAppleEventDescriptor descriptorWithString:_storagePath];
NSAppleEventDescriptor *secondParameter = [NSAppleEventDescriptor descriptorWithString:[NSString stringWithFormat:@"%@, %@, %@", [_spider rootString], _sourceURL, _parentWebPage]];
// create and populate the list of parameters
// note that the array starts at index 1
NSAppleEventDescriptor *parameters = [NSAppleEventDescriptor listDescriptor];
[parameters insertDescriptor:firstParameter atIndex:1];
[parameters insertDescriptor:secondParameter atIndex:2];
// create the AppleEvent target
ProcessSerialNumber psn = { 0, kCurrentProcess };
NSAppleEventDescriptor *target = [NSAppleEventDescriptor descriptorWithDescriptorType:typeProcessSerialNumber bytes:&psn length:sizeof(ProcessSerialNumber)];
// create an NSAppleEventDescriptor with the method name
// note that the name must be lowercase (even if it is uppercase in AppleScript)
NSAppleEventDescriptor *handler = [NSAppleEventDescriptor descriptorWithString:[@"setSpotlightComment" lowercaseString]];
// last but not least, create the event for an AppleScript subroutine
// set the method name and the list of parameters
NSAppleEventDescriptor *event = [NSAppleEventDescriptor appleEventWithEventClass:kASAppleScriptSuite eventID:kASSubroutineEvent targetDescriptor:target returnID:kAutoGenerateReturnID transactionID:kAnyTransactionID];
[event setParamDescriptor:handler forKeyword:keyASSubroutineName];
[event setParamDescriptor:parameters forKeyword:keyDirectObject];
// at last, call the event in AppleScript
if(![[_spider commentScript] executeAppleEvent:event error:&errors])
[[_spider session] logComment:@"Could not set Finder Spotlight comment" forResourceID:[self resourceID]];


Hope this helps!

John


On Feb 12, 2007, at 5:07 AM, Pierre Bernard wrote:

Is there an API for writing Spotlight comments (aka. Finder comments) for files?




- - - Houdah Software s. à r. l. http://www.houdah.com - Quality Mac OS X software - Premium WebObjects consulting




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Writing Spotlight comments (From: Pierre Bernard <email@hidden>)
 >Re: Writing Spotlight comments (From: John Pannell <email@hidden>)

  • Prev by Date: Re: how to set the shortcut key in the interface builder?
  • Next by Date: Printing crash
  • Previous by thread: Re: Writing Spotlight comments
  • Next by thread: how to set the shortcut key in the interface builder?
  • Index(es):
    • Date
    • Thread