8 Replies Latest reply: Jun 13, 2008 2:05 PM by theparakeet
mmcrider Level 1 Level 1 (0 points)
I have written an automator, based on a suggestion found at this site, that appends comments to the spotlight comments. I can even delete existing comments. But, what I don't seem to be able to do is to GET EXISTING comments and make a change to these existing comments - add additional comments, if necessary - and enter then new comments back into spotlight comments.

Does anyone have any ideas?

Thanks.

Matt

Mac OS X (10.5.1), iMac and MacBook Pro
  • 1. Re: GET spotlight comments automator?
    red_menace Level 6 Level 6 (14,615 points)
    You can open an application's dictionary from the Script Editor to see what scripting commands are supported and what properties are defined. In this case, a Finder item has a comment property that you can read and write, for example:

    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    set TheFIle to (choose file without invisibles) -- get some file
    tell application "Finder"
    set TheComment to the comment of TheFIle -- get the comment
    display dialog ("Change the comment for" & return & "\"" & (TheFIle as text) & "\" ?") with title "Edit Spotlight Comment" default answer TheComment -- edit the comment
    set comment of TheFIle to text returned of the result -- set the comment
    end tell
    </pre>

    Note that the return or enter key will select the OK button, but you can use any of AppleScript's text handling methods on the comment string.
  • 2. Re: GET spotlight comments automator?
    dev_sleidy Level 4 Level 4 (1,570 points)
    Save the code presented below as an application.

    Launch (run) the application to select a file for 'comment' processing; or, drag items onto the applet for each items' 'comment' field to be processed.

    --- Code starts here ---
    on open (ditems)
    repeat with i in ditems -- Cycle through list of dragged items.
    my handle_Item(i) -- Process each item.
    end repeat
    end open

    on run
    my handle_Item(choose file without invisibles) -- Select file to process.
    end run

    on handle_Item(tItem)
    tell application "Finder" to set (comment of tItem) to (text returned) of (display dialog (tItem as string) with title "Spotlight Comment: " default answer (comment of tItem) as string) -- Display and accept modification of 'comment' field contents.
    end handle_Item
    --- Code ends here ---

    To process a file or folder via launching the applet ...

    --- Code starts here ---
    on open (ditems)
    repeat with i in ditems -- Cycle through list of dragged items.
    my handle_Item(i) -- Process each item.
    end repeat
    end open

    on run
    if (((button returned) of (display dialog "Make a selection:" buttons {"Cancel", "File", "Folder"} default button 2)) is "File") then
    my handle_Item(choose file without invisibles) -- Select file to process.
    else
    my handle_Item(choose folder) -- Select folder to process.
    end if
    end run

    on handle_Item(tItem)
    tell application "Finder" to set (comment of tItem) to (text returned) of (display dialog (tItem as string) with title "Spotlight Comment: " default answer (comment of tItem) as string) -- Display and accept modification of 'comment' field contents.
    end handle_Item
    --- Code ends here ---
  • 3. Re: GET spotlight comments automator?
    mmcrider Level 1 Level 1 (0 points)
    Ok, this works very well indeed! However, I was thinking more along the lines of doing one file at a time. How can I select a file in the finder and then invoke this script to return the comments for editing for the ALREADY SELECTED file, instead of invoking the program and picking the file then?

    Thanks.

    Matt
  • 4. Re: GET spotlight comments automator?
    dev_sleidy Level 4 Level 4 (1,570 points)
    01. The code (of red_menace and myself) above, does process one (1) item (file or folder) at a time.
    02. If you desired an Automator Plug-in - then such should have been explicitly stated in the original post.

    Solution to latest request:

    01. Launch 'Automator'.
    02. Select 'Automator' from 'Library'.
    03. Double click on 'Run AppleScript'. A 'Run AppleScript' module will appear in the right side column.
    04. In the 'Run AppleScript' module, replace ...

    {* your script goes here *}

    ... with ...

    tell application "Finder"
    repeat with tItem in input
    set (comment of tItem) to (text returned) of (display dialog "Spotlight Comment: " default answer (comment of tItem as string))
    end repeat
    end tell

    05. Check the spelling and syntax of the code.
    06. Save the code as an 'Automator Plug-In' file.

    The above code was tested on a MacBook running MacOS X 10.5.2 (a.k.a. - dog crap).

    ---

    Sadly, with 'Leopard' one has to now select the asinine contextual menus' 'More...' menu item, to select the asinine 'Automator' (or other installed contextual menu files) menu item, to finally select the desired 'Automator Plug-In'.
  • 5. Re: GET spotlight comments automator?
    benben29 Level 1 Level 1 (0 points)
    Hi there,

    maybe someone can help me.
    i should say that i have absolutely no idea about apple script.
    I want to create an automator plugin that takes the spotlight comments of a chosen photo and copies these to an iptc field.

    I think the above script would be the right starting point but then there must be some command that uses GraphicConverter or something similar to write to iptc.

    Looking forward to your answers, thx in advance
    ben
  • 6. Re: GET spotlight comments automator?
    theparakeet Level 1 Level 1 (85 points)
    I think s/he was actually asking how to interrogate a file for its Spotlight comments. And so am I...

    There's an action to "Set Spotlight Comments For Finder Items" - but there's no corresponding opportunity to find files based on their Spotlight comments.

    This should be in the Find Finder Items - but it's not.

    I want to perform a task on some files in a folder, then change some property so that I can exclude those files the next time the workflow runs. I'd use iPhoto keywords but, conversely, whilst I can identify files by their keywords via Find Finder Items, I can't see a way to set those keywords.

    Any ideas?
  • 7. Re: GET spotlight comments automator?
    theparakeet Level 1 Level 1 (85 points)
    In fact, on closer inspection, the Find Finder Items action CAN see Spotlight comments - you just need to use the ANY part of the dropdown.
  • 8. Re: GET spotlight comments automator?
    theparakeet Level 1 Level 1 (85 points)
    Correction - I think I'm wrong on the above - the ANY field.