How to label and tag files with smart folders?

I’ve set up smart folders to enable me to label and organize files as High, Medium and Low priority. I’ve tried to also enable my smart folders to tag and organize files through the same priority schema, but I haven’t yet made it work. Right now the settings for my smart folders are as follows:

ALL of the following are true
Label is Low
Kind is Any Document

I later included…

Tag is Low

And toggled “ALL / ANY of the following are true” - neither worked.

How I should I fix this to allow the smart folders to label and tag files?

Thanks!

Is it even possible to create two such rules for smart folder? - i.e., enabling them to label and tag files?

Thanks.

jprint:

I am a little confused as Smart Folders don’t function as controllers. For example, I make a Smart Group showing files that are labelled “Important”. This exposes files that have the label but I cannot drop files on this group to label them. It only shows me results.

A Tag group is a different sort of animal in that it does allow you to tag a file by drag and drop. Is this what you’re looking at?

Thanks for your reply!

Right now, when I label files through the aforementioned smart folder set up, it works perfectly. I was hoping to just add a Tag function to the smart folder set up that would enable me to tag a file with the same priority system, and have it show up in the respective smart folders. Is this possible?

Thank you…

Just to clarify my usage…

I tend to Label messages that are already stored in my DTP databases - and these labeled files appear in my smart folders.

I would like to Tag files that I’m about to store in my DTP databases - using these same priority schema, so that these tagged files also appear in the same smart folders.

Is this possible? Thank you again…

This is how you want to set up your smart group. Enter the kind is any document criteria, then option-click the ‘+’ button to create the compound predicate.

Thank you! But…I don’t see an option for “Any” in the smart folder set up… Do I need to toggle something? Please advise when possible. Thanks so much!

Enter the kind is any document criteria, then option-click the ‘+’ button to create the compound predicate. When you do that, the default for the new options should be Any. If it is not, click on All to change it to Any.

Hmmm. Strange. I’ve followed all of your steps, but it’s set at All - can’t seem to change it for Any.

Suggestions?

What happens when you click on All? When you click on any of the Smart Group fields with the double-arrows, you get a pop-up to toggle the criteria.

Ok, so regardless of whether I select All or Any, I don’t get another field that offers anything like “Any” and “of the following are true.” I don’t see any way to switch All to Any (except for the first field) and don’t see anything that allows me to select “of the following are true.”

Got it! I apologize - I didn’t see the part about using the option key until I reread your instruction.

One quick follow up question… Should Ignore Diacriticts be check or unchecked? In my previous set up it was checked.

Anyway, thank you again!

I am still confused. print, you write as if you are using the Smart Groups to actually apply labels and tags to files. Just for my sanity and edification, could you clarify how you are tagging and labeling your files? Thanks. 8^)

Sorry to be confusing. I’ve been using labels to consolidate files into a Smart Group. Thanks to @korm, I was able to then use the following trigger script to apply prefixes to labeled files that were in my groups (within my database):

on triggered(theRecord)
   try
      tell application id "com.devon-technologies.thinkpro2"
         
         set theSelection to the every child of theRecord
         -- set theSelection to selection
         set labelCount to 0
         -- display dialog "DEBUG at First Setting"
         repeat with thisItem in theSelection
            -- display dialog "DEBUG at Inside repeat"
            -- first we get rid of existing prefixes
            -- "1_" == I. Urgent, "2_" == II. High, "3_" == III. Moderate
            set myName to the name of thisItem
            if (the name of thisItem contains "1_") then
               set myName to my trim_line(myName, "1_", 0)
            else if (the name of thisItem contains "2_") then
               set myName to my trim_line(myName, "2_", 0)
            else if (the name of thisItem contains "3_") then
               set myName to my trim_line(myName, "3_", 0)
            end if
            
            -- next we assign new prefixes, or none, based on the current label
            -- label 1 == High, 2 == Medium, 3 == Low
            if the label of thisItem is 1 then
               set the name of thisItem to "1_" & myName
               set labelCount to labelCount + 1
            else if the label of thisItem is 2 then
               set the name of thisItem to "2_" & myName
               set labelCount to labelCount + 1
            else if the label of thisItem is 3 then
               set the name of thisItem to "3_" & myName
               set labelCount to labelCount + 1
            else
               set the name of thisItem to myName
            end if
         end repeat
         
      end tell
      set Notified to my growlMe((labelCount as string) & " items were updated by Set Prefix Depending on Label")
   end try
end triggered

-- Attribution: this "trim_line" sub-routine was provided by
-- http://www.macosxautomation.com/applescript/sbrt/sbrt-06.html

on trim_line(this_text, trim_chars, trim_indicator)
   -- 0 = beginning, 1 = end, 2 = both
   set x to the length of the trim_chars
   -- TRIM BEGINNING
   if the trim_indicator is in {0, 2} then
      repeat while this_text begins with the trim_chars
         try
            set this_text to characters (x + 1) thru -1 of this_text as string
         on error
            -- the text contains nothing but the trim characters
            return ""
         end try
      end repeat
   end if
   -- TRIM ENDING
   if the trim_indicator is in {1, 2} then
      repeat while this_text ends with the trim_chars
         try
            set this_text to characters 1 thru -(x + 1) of this_text as string
         on error
            -- the text contains nothing but the trim characters
            return ""
         end try
      end repeat
   end if
   return this_text
end trim_line

-- for information on scripting Growl see
-- http://growl.info/documentation/applescript-support.php
on growlMe(myNotification)
   tell application "System Events"
      set isRunning to (count of (every process whose bundle identifier is "com.growl.growlhelperapp"))
   end tell
   if isRunning = 1 then
      tell application id "com.growl.growlhelperapp"
         set the allNotificationsList to {"Script Status", "Failure"}
         set the enabledNotificationsList to {"Script Status", "Failure"}
         register as application "DEVONthink Script" all notifications allNotificationsList default notifications enabledNotificationsList
         notify with name "Script Status" title "DEVONthink Script Status" description myNotification application name "DEVONthink Script" with sticky
      end tell
   end if
end growlMe

This was @korm’s ingenious idea, and was borne out of this forum discussion:

[url]A better way to use MobileSync with GoodReader?]

I was actually hoping that the Smart Folder set up you helped create would allow me to use the same script for Tagged items. But there’s one drawback… Even if the set up you created places Tagged items in the appropriate smart folder (e.g., those files tagged as “Low” now appear in the Low smart folder) they are not labeled as low, so @korm’s script doesn’t apply, of course!

Do you know if there’s a way to make a Tagged item automatically be assigned a particular label? If so, all my problems are solved!

Thank you again…

A smart group, per se, doesn’t’t contain any documents. What it “contains” is search criteria such that when the smart group is opened, it displays the list of search results.

This is probably an unintended feature, but triggered scripts can be applied to smart groups, just as they can be applied to any other group. When the smart group is selected, then the script is executed. This way, a script attached to a smart group can change tags, change names, or do anything else that a script can do.

For example, if this script is attached to a smart group, then it will add a specific tag to every record found by that smart group. Be careful to follow the exact instructions: the smart group has to be selected first before the script will execute.

on triggered(theRecord)
	try
		tell application id "com.devon-technologies.thinkpro2"
			set theSelection to the children of theRecord
			repeat with thisItem in theSelection
				set the tags of thisItem to (the tags of thisItem & "Nonce")
			end repeat
		end tell
	end try
end triggered

I’m not going to write scripts for anyone, but if jprint714 wants to play with this concept then the outcome requested above in this thread will result. I’ve tested this, and it works.

Just to add one note on attaching scripts to smart groups-the smart groups must be in the database. It is not possible to bring up the Info panel on a smart group located in the DEVONthink Sidebar, so there is no way to attach a script.

To set labels via a script, you would want to add this to korm’s script:


set the label of thisItem to x

where x (no quotation marks needed) is a number 0-7, where 0 is no label and 1 thru 7 corresponds to the 7 labels in DEVONthink’s preferences.

Thanks so much for this… To clarify, I’m seeking a way that a label that I attach to file automatically receives a tag (e.g., if I give a file a “Low” tag, I’d like it to receive a “High” label). Just want to make sure we’re on the same page. I understand this script needs to be tailored, but will it generally provide that for that?

Thanks!

If you make a smart group where tag=Low, and attach a script to that smart group to add the label High (1-7) to all documents in that smart group, then yes-this will do what you want. However you will, as korm pointed, need to select the smart group to trigger the attached script.

Having said that, I personally fail to see the logic of having this redundancy. If the documents have already been tagged Low, why do you need additional metadata (label=High) that duplicates what the tag does?

Thanks so much… I’m just starting to understand how to use scripts, so I’ll tinker w/ script to try to make it work. Hope it can work… If not, I’ll dash off a follow up question.

You ask a totally reasonable question. In short, it relates to another post I submitted re: how to automate a process whereby prefixes could be applied to files that corresponded to certain applied labels (High, Medium, Low priority). @korm very generously provided the following script:

on triggered(theRecord)
   try
      tell application id "com.devon-technologies.thinkpro2"
         
         set theSelection to the every child of theRecord
         -- set theSelection to selection
         set labelCount to 0
         -- display dialog "DEBUG at First Setting"
         repeat with thisItem in theSelection
            -- display dialog "DEBUG at Inside repeat"
            -- first we get rid of existing prefixes
            -- "1_" == I. Urgent, "2_" == II. High, "3_" == III. Moderate
            set myName to the name of thisItem
            if (the name of thisItem contains "1_") then
               set myName to my trim_line(myName, "1_", 0)
            else if (the name of thisItem contains "2_") then
               set myName to my trim_line(myName, "2_", 0)
            else if (the name of thisItem contains "3_") then
               set myName to my trim_line(myName, "3_", 0)
            end if
            
            -- next we assign new prefixes, or none, based on the current label
            -- label 1 == High, 2 == Medium, 3 == Low
            if the label of thisItem is 1 then
               set the name of thisItem to "1_" & myName
               set labelCount to labelCount + 1
            else if the label of thisItem is 2 then
               set the name of thisItem to "2_" & myName
               set labelCount to labelCount + 1
            else if the label of thisItem is 3 then
               set the name of thisItem to "3_" & myName
               set labelCount to labelCount + 1
            else
               set the name of thisItem to myName
            end if
         end repeat
         
      end tell
      set Notified to my growlMe((labelCount as string) & " items were updated by Set Prefix Depending on Label")
   end try
end triggered

-- Attribution: this "trim_line" sub-routine was provided by
-- http://www.macosxautomation.com/applescript/sbrt/sbrt-06.html

on trim_line(this_text, trim_chars, trim_indicator)
   -- 0 = beginning, 1 = end, 2 = both
   set x to the length of the trim_chars
   -- TRIM BEGINNING
   if the trim_indicator is in {0, 2} then
      repeat while this_text begins with the trim_chars
         try
            set this_text to characters (x + 1) thru -1 of this_text as string
         on error
            -- the text contains nothing but the trim characters
            return ""
         end try
      end repeat
   end if
   -- TRIM ENDING
   if the trim_indicator is in {1, 2} then
      repeat while this_text ends with the trim_chars
         try
            set this_text to characters 1 thru -(x + 1) of this_text as string
         on error
            -- the text contains nothing but the trim characters
            return ""
         end try
      end repeat
   end if
   return this_text
end trim_line

-- for information on scripting Growl see
-- http://growl.info/documentation/applescript-support.php
on growlMe(myNotification)
   tell application "System Events"
      set isRunning to (count of (every process whose bundle identifier is "com.growl.growlhelperapp"))
   end tell
   if isRunning = 1 then
      tell application id "com.growl.growlhelperapp"
         set the allNotificationsList to {"Script Status", "Failure"}
         set the enabledNotificationsList to {"Script Status", "Failure"}
         register as application "DEVONthink Script" all notifications allNotificationsList default notifications enabledNotificationsList
         notify with name "Script Status" title "DEVONthink Script Status" description myNotification application name "DEVONthink Script" with sticky
      end tell
   end if
end growlMe 

It works perfectly, and brilliant helps me triage my files. But…I was just trying to get it to work with tags; right now it just works with labels. So, it seemed to me that if I could figure out how a process to automatically label a file that has a corresponding tag (a “Low” tag would receive a “Low” label), then I could retain the functions provided in @korm’s script. I’m happy to consider another process…I welcome any other suggestions.

I’ve asked this just because…I find that it’s preferable to Label files that are already in DTP, but it’s also easier to Tag files that I’m saving into DTP (esp. web files). That’s all…

Thanks, guys!