Skip navigation

Applescript that scans for labels?

305 Views 5 Replies Latest reply: Feb 20, 2013 4:25 AM by HD RSS
Ga776m Calculating status...
Currently Being Moderated
Feb 19, 2013 11:35 AM

Does anyone know if applescript can scan for finder labels? I am wondering because I tried to have an automator workflow scan recursively (until I learned automator does not work recursively) for all the files in my home directory with the gray label "unimportant" and move them to a folder on the desktop for my review and then subsequent deletion.

 

The only thing is that it obviously does not work, and I have no clue how to use Applescript. Any ideas?

 

 

 

Thank You,

 

Ga776m

MacBook Pro, OS X Mountain Lion (10.8.1), Mid-2012
  • twtwtw Level 5 Level 5 (4,580 points)
    Currently Being Moderated
    Feb 19, 2013 11:38 AM (in response to Ga776m)

    If I were you I'd just use a smart folder, no need for applescript.

  • HD Level 4 Level 4 (3,240 points)
    Currently Being Moderated
    Feb 19, 2013 2:05 PM (in response to twtwtw)

    I have found (reproducibly) that if you set up a smart folder to search for a coloured label, and then change the label colour of any of the files returned by the search, the smart search will continue to return that file. For example, I run a smart search for files with a grey label, and then change one of the labels to red:

     

    Screen Shot 2013-02-19 at 21.33.59.png

     

    The red file is still returned by the grey search.

     

    (Thinks - must file a bug report.)

     

    The same happens if you DO use an AppleScript:

     

    set found_files to paragraphs of (do shell script "mdfind " & quoted form of "kMDItemFSLabel = 1") --search for grey files

    tell application "Finder"

              try

                        set the_folder to (make new folder at desktop with properties {name:"For Review"}) --create the target folder if it doesn't already exist

              end try

    end tell

    repeat with each_file in found_files -- move all the files to the target folder

              set each_file to file each_file

              tell application "Finder"

      move each_file to the_folder without replacing

              end tell

    end repeat

     

     

    This moves the red file (originally labelled grey) to the "For Review" folder along with any grey ones. It doesn't have to be recursive because it used the power of mdfind.

     

    Like I say, it may not be an issue if the OP doesn't want to change the labels of the grey files.

     

    But I'd be interested to know if anyone else sees the same apparent misbehaviour.

     

    H


  • HD Level 4 Level 4 (3,240 points)
    Currently Being Moderated
    Feb 19, 2013 2:23 PM (in response to HD)

    (The relabelled red file is also found by a "red" search.)

  • twtwtw Level 5 Level 5 (4,580 points)
    Currently Being Moderated
    Feb 19, 2013 4:56 PM (in response to HD)

    I can't replicate this on my laptop.  using the File Label search criterion, if I change the label color it instantly switches from one group to the next.  Is your computer indexing the folder you're looking at?  if not, you might want to force it to reindex everything overnight.

  • HD Level 4 Level 4 (3,240 points)
    Currently Being Moderated
    Feb 20, 2013 4:25 AM (in response to twtwtw)

    Thanks, I'll check that out. The items are in folders across the system and are presented in a folder-like display by the smart search, but they aren't all in the same location. This probably needs a separate thread so I shall stop here!

Actions

More Like This

  • Retrieving data ...

Bookmarked By (1)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.