Use tags to select files

Hi,
There must be a way to select all files with xx colored tag. And then do something with them. I want to import them into Devon Think Office Pro. But, to do that, I think I need script from the library of DTOP. Not sure how to even look for that script.
If I can’t do that, I can do it manually.
Thanks,
Ellen

Presuming the files are either selected in the Finder or in a folder, you use a For Each action to iterate over all of them.

You then use the Get File Attribute to get the tags of the file, and then an If Then Else action with a Variable condition to test for the existence of the tag. And then within the If action, you process the file.

I want to select the file that has the tag. The name of the tag is "refile." . I don't anything happening. Perhaps I am not doing the right thing to select the files with the tag "refile". Perhaps I don't know how to test it.

Hey Ellenm,

To do this in Keyboard Maestro you have to iterate through a collection of file paths and test each one for the attribute you’re looking for.

In general I prefer to do it from the shell:

mdfind -onlyin '/Users/chris/test_directory/Tags_Test/' "kMDItemUserTags == KM"

And that translates well into AppleScript:

------------------------------------------------------------
set searchDir to "/Users/chris/test_directory/Tags_Test/" # Posix Path
set destinationDir to alias ((path to home folder as text) & "test_directory:mv_destination:") # Alias
set shCMD to "mdfind -onlyin " & quoted form of searchDir & " \"kMDItemUserTags == KM\""
set fileList to do shell script shCMD

if fileList ≠ "" then
  set fileList to paragraphs of fileList
  
  repeat with i in fileList
    set (contents of i) to alias POSIX file (contents of i)
  end repeat
  
  tell application "Finder"
    duplicate fileList to destinationDir
  end tell
  
end if
------------------------------------------------------------

The tag in question in the script is ‘KM’ (no quotes). A multi-word-tag might need them, but I’m not going to test.

The script turns the found file’s Posix Paths into an alias list, because that can be moved en mass via the Finder.

You can move instead of duplicate. I’ve used dupe for safety here.

I generally don’t like hard-coding locations in scripts (unless necessary), so here’s one that operates on the front window in the Finder.

-----------------------------------------------------------
# Operates on the front window in the Finder
-----------------------------------------------------------
tell application "Finder"
  set searchDir to get insertion location as text
end tell
set searchDir to POSIX path of searchDir

set shCMD to "mdfind -onlyin " & quoted form of searchDir & " \"kMDItemUserTags == KM\""
set fileList to do shell script shCMD
-----------------------------------------------------------

I’m certain you can import files into DEVONThink Pro Office via AppleScript.

I do not know if you can cause DTPO to index them in place in the Finder via AppleScript.

DTPO appears to accept Posix Paths in the import command, so I would not use the loop to turn them into aliases in that case.

-Chris