• 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: Adding Spotlight keywords to files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding Spotlight keywords to files


  • Subject: Re: Adding Spotlight keywords to files
  • From: Guy English <email@hidden>
  • Date: Sun, 7 Aug 2005 22:01:09 -0400

Hey Jeroen,

    Thanks for the code pointer, I'm going to nick that because it's
handy to have around.  Less handy are the two memory leaks though. :)
scriptError and appleScript both leak - they're sent allocs but have
no matching release or autorelease. Also, even when you add a release
for the scriptError it'll leak anyway. :) executeAndReturnError: will
overwrite the pointer to the dictionary with the dictionary it creates
internally. It's not a very common idiom in Cocoa ( although there are
a few places that do use it ) but it's something to watch out for.

    Here's the adjusted code below. Thanks for putting it up - the
image color automater thing is a very cool idea by the way. Try adding
face recognition and it'd be super-duper cool. :)

Take care,
Guy

-(void)setCommentForFile:(NSString*)file
               toComment:(NSString*)comment
{
    NSDictionary *scriptError = nil;

    /* Create the Applescript to run with the filename and comment string... */
    NSString *scriptSource = [NSString stringWithFormat:
        @"on run\r tell application \"Finder\"\r set theFile to
        (\"%@\") as alias\r set newComment to (comment of theFile) &
        \"%@\"\r set comment of theFile to newComment\r end tell\r end run\r",
        [self carbonPathFromPath:file], comment];

    NSAppleScript *appleScript = [[NSAppleScript alloc]
initWithSource:scriptSource];

    /* Run the script! */
    if(![appleScript executeAndReturnError:&scriptError])
        NSLog([scriptError description]);

    [appleScript release];
}


On 8/7/05, Jeroen Verbeek <email@hidden> wrote:
> Adding Finder/Spotlight comments can be done several ways, I chose to
> use Applescript executed from Cocoa.
>
> Have a look at: http://www.happymakinggames.com/code/2005/7/23/23.html
>
> Have fun!
>
> Jeroen.
>
> On 07/08/2005, at 3:24 PM, Guy English wrote:
>
> > Hi,
> >
> >     You could append "screenshot" into the Finder ( now Spotlight )
> > comments field. You'll need to look into Carbon stuff, the comments
> > are stored in the resource fork I believe.
> >
> > Guy
> >
> >
> > On 8/5/05, Ben Haller <email@hidden> wrote:
> >
> >>    Hi!  I've been poking through developer docs and list archives for
> >> a while, and I believe this question remains unanswered, although I
> >> saw it asked a few times by others:
> >>
> >>    Can an app simply add metadata to an existing file (one it
> >> creates, even), without being the owner of that file and without
> >> having an "importer"?  If not, is this because there just isn't API
> >> to do it at the moment, or is this idea in fact contrary to the
> >> design of Spotlight?
> >>
> >>    A practical example.  I have a screenshot app.  It lets the user
> >> choose what other app will "own" the screenshots it saves; you can
> >> make them be GraphicConverter files, Photoshop files, Preview files,
> >> whatever.  My app is not itself capable of opening image files at
> >> all; it can only create them.  So obviously my app cannot have a
> >> Spotlight importer.
> >>    I want my app to tag all the files it creates as being
> >> "screenshots" by tagging them with a keyword.  This would let the
> >> user quickly and easily find screenshots they had taken, regardless
> >> of where they had ended up, and that strikes me as useful.  If
> >> Spotlight can't do things like that, I think users will be
> >> disappointed...
> >>
> >>    I haven't seen this explicitly stated, but the more I read, the
> >> more I get the impression that a stake for Spotlight is that the
> >> metadata for a file must always be able to be regenerated from the
> >> file's data; metadata can never contain its own unique information,
> >> it can only hold up a mirror, as it were, to the data already in the
> >> file.  If this is true, then presumably there will never be a way for
> >> the user to just tag a bunch of files as being "related to project
> >> XYZ"; if that metadata were lost, there would be no way to recreate
> >> it, since the files themselves don't know they are part of project
> >> XYZ.  Such a tag would violate the fundamental design of Spotlight.
> >> Is this correct?  If so, it seems like a major, major limitation.
> >>
> >> Ben Haller
> >> Stick Software
> >>
> >>
> >>  _______________________________________________
> >> Do not post admin requests to the list. They will be ignored.
> >> Cocoa-dev mailing list      (email@hidden)
> >> Help/Unsubscribe/Update your Subscription:
> >> 40gmail.com
> >>
> >> This email sent to email@hidden
> >>
> >>
> >  _______________________________________________
> > Do not post admin requests to the list. They will be ignored.
> > Cocoa-dev mailing list      (email@hidden)
> > Help/Unsubscribe/Update your Subscription:
> >
> > This email sent to email@hidden
> >
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Adding Spotlight keywords to files (From: Ben Haller <email@hidden>)
 >Re: Adding Spotlight keywords to files (From: Guy English <email@hidden>)
 >Re: Adding Spotlight keywords to files (From: Jeroen Verbeek <email@hidden>)

  • Prev by Date: Converting image types and preserving EXIF.
  • Next by Date: Re: Modifying bitmap data
  • Previous by thread: Re: Adding Spotlight keywords to files
  • Next by thread: Re: Adding Spotlight keywords to files
  • Index(es):
    • Date
    • Thread