Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

(From OSX 10.6.8)

I would like to set up an Automator workflow that adds ( "Archived" + Current Date ) to a root folder/files and all files/subfolders' spotlight comments

EXCEPT

where an "Archived" tag already exists.

This is so I can run the workflow on the root folder and not have a bunch of "Archived" tags appended to files/folders all stacking up.

Any thoughts? I am trying to filter out some tags then continue running a workflow based on the remainder.

share|improve this question
    
Does it have to be in Automator? – slhck Jul 18 '12 at 3:12
    
Not necessarily. I don't mind a solution in Terminal etc. Although, I was hoping to also change the file/folder Label to Red as well, for immediate visual confirmation. Maybe that can be done too? – James Jul 18 '12 at 5:21
up vote 1 down vote accepted

Finder folder objects have an entire contents attribute in AppleScript, and it's easy to set Spotlight comments and color labels.

set d to do shell script "date +%Y-%m-%d"
tell application "Finder"
    set dir to POSIX file ((system attribute "HOME") & "/Documents/Test") as alias
    repeat with f in entire contents of dir
        if comment of f does not start with "Archived" then
            set comment of f to "Archived " & d
            set label index of f to 2
        end if
    end repeat
end tell

Shell script version:

#!/bin/bash

d=$(date +%Y-%m-%d)
find ~/Documents/Test -exec osascript -e "on run argv
repeat with f in argv
tell app \"Finder\"
set f to (posix file (contents of f)) as alias
if comment of f does not start with \"Archived\" then
set comment of f to \"Archived $d\"
set label index of f to 2
end
end
end
end" '{}' +
share|improve this answer
    
Thanks mate, I'll have a look at this this morning! Cheers. – James Jul 18 '12 at 23:12
    
Awesome! Works a treat, Lri you are a legend! – James Jul 19 '12 at 1:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .