Page 1 of 1

Multiple Spotlight Comments, Filing System?

PostPosted: Wed Jul 11, 2012 10:59 pm
by nphowery
Hi all,

I'm hoping someone can help me address a Spotlight and Filing issue I have been trying to work around. I normally add several spotlight comments to files that I save. For example, one PDF can have the following tags: tag1, tag2, tag3, tag4.

What I would like to ideally do is set up Hazel to watch a folder into which I would drop the PDF mentioned above. It would look for Spotlight Comments, and copy the PDF into another folder whose name matches the tag I used. For example, I would have a folder called "Tag1", another called "Tag2", etc. I would drop a file into the folder being watched by Hazel. Hazel would see the Spotlight Comment "Tag1" and create a copy of the file in folder "Tag1".

Unfortunately, I am coming across several semi-related issues:
1) First, it seems only the first comment in a string of Spotlight Comments is being recognized. So, only one copy would be created: in the folder "Tag1". I would like additional copies to be created in "Tag2", "Tag3", etc.
2) I would like to avoid creating 350 separate rules for my 350 folders. I am hoping a more generic rule (or script) could be created. ("If Spotlight Comment is not empty, copy file into folder matching any of the Spotlight Comments", etc).

Any thoughts would be much appreciated. The solution might be something totally different from where I've started; I'm basically just looking to automate my filing in some way.

Thank you!

Re: Multiple Spotlight Comments, Filing System?

PostPosted: Thu Jul 12, 2012 2:39 pm
by Mr_Noodle
Read the help on "match patterns". I believe that should do what you want.

Re: Multiple Spotlight Comments, Filing System?

PostPosted: Thu Jul 12, 2012 3:13 pm
by a_freyer
I'm not sure that Match Patterns is going to work in this situation because of the OP's requirement of copying the file into all tag subfolders.

EDIT - Matching is the way to go, but we need sequential rules. See my answer below.

How are your tags delimited in the spotlight comments? Do you have anything else in the spotlight comments for these PDFs?

Re: Multiple Spotlight Comments, Filing System?

PostPosted: Thu Jul 12, 2012 5:51 pm
by nphowery
When I type the tags into the Spotlight Comments section, I usually type the word and a comma after it, leaving a space after that. ("manufacturing, ")

Are there other ways of separating the tags that might help me get to the system I would like? Thanks so much for the quick reply.

Re: Multiple Spotlight Comments, Filing System?

PostPosted: Thu Jul 12, 2012 6:35 pm
by a_freyer
I have a working version for this workflow:

(1) Place file in a /Monitored Folder/ with comma-delimited tags.
(2) File name is prepended with [full tag list] in brackets
(3) The first tag in the file name list is removed, and the file is copied into the proper directory without the prepended tag list
(4) Once the last tag has been reached, the file is removed from /Monitored Folder/ and a growl notification is sent.

I use this workflow in order to keep the comments in each file.

In the end, the result is this:

Image

There are three rules, and their order is important:

Rule #1: Rename Files with Comments as Prependate
Code: Select all
if (all) of the following conditions are met for (the file or folder being matched)
    Kind is not Folder
    Comment matches (All Comments •)
    Name does not match [(...)](...)

Do the following to the matched file or folder:
    Set color label Orange
    Rename with pattern [ (All Comments •) (name)(extension)

A custom matching token is used in rule 1 to match the list of comments. The criteria for this custom token is (...)


Rule #2: Remove First Tag & Copy
Code: Select all
if (all) of the following conditions are met for (the file or folder being matched)
    Name matches [(First Tag in List •), (Remainder of Tags•)] (Remainder of Filename•)

Do the following to the matched file or folder:
    Rename with pattern [(Remainder of Tags •)] (Remainder of Filename •)
    Copy to folder /Final Sorting Directory/
    Sort into Subfolder with pattern (First Tag in List •)
    Rename with pattern (Remainder of Filename •)
    Set Color Label Clear

Three custom matching tokens are used in rule 2 to match the first comment, the remainder of comments, and the remainder of the file name. Each of these are merely an (...)


Rule #3: Remove Last Tag & Sort
Code: Select all
if (all) of the following conditions are met for (the file or folder being matched)
    Name matches [(First Tag in List •)] (Remainder of Filename•)

Do the following to the matched file or folder:
    Rename with pattern (Remainder of Filename •)
    Move to folder /Final Sorting Directory/
    Sort into Subfolder with pattern (First Tag in List •)
    Send Growl Alert with pattern (Remainder of Filename •) has been sorted into all applicable directories.
    Set Color Label Clear

Two custom matching tokens are used in rule 2 to match the only remaining comment and the remainder of the file name. Each of these are merely an (...)

Because this will take a long time to setup, I've hosted the rule on dropbox.


You will probably have to tailor this to your exact needs, but hopefully this gets you going in the correct direction.

Happy Hazeling!

Re: Multiple Spotlight Comments, Filing System?

PostPosted: Fri Jul 13, 2012 2:59 pm
by Mr_Noodle
Wow, a_freyer. Thanks again for stepping in and helping out. I guess I'm not needed here. :o

Re: Multiple Spotlight Comments, Filing System?

PostPosted: Fri Jul 13, 2012 3:02 pm
by a_freyer
Mr_Noodle wrote:Wow, a_freyer. Thanks again for stepping in and helping out. I guess I'm not needed here. :o


Haha, glad to help.

Re: Multiple Spotlight Comments, Filing System?

PostPosted: Fri Jul 13, 2012 5:01 pm
by nphowery
Hi a_freyer,

Thank you so, so much for the rule. So far it seems to be working pretty well. I've only run into two small issues. The first is that sometimes the rule creates the file twice in one folder. I think what is happening is that if the folder for the tag does not exist, the rule starts all over again.

For example, if a file has two tags (tag1, tag2) attached, and if the folder for tag2 does not already exist, the rule starts all over again. So the tag1 folder ends up getting two copies: 1 when the rule runs the first time and 1 when it reruns to create the folder for tag2. Any thoughts would be much appreciated.



Separately, I'm wondering if there is any way to run the rule on a whole tree of folders. For example, I have a folder called Industry Research. Inside this folder there are 35-45 folders. For example, one might be Oil & Gas. Inside Oil & Gas, there may be 4-7 more folders: Natural Gas, Exploration, etc.

As an example: Industry Research > Oil & Gas > Natural Gas

The way I am running the rule right now, I have copied the rule onto each of the higher level folders. In the example above, I copied the rule to run on the Industry Research. If I add a a file that has the tags "Oil & Gas" and "Natural Gas", the file will get copied to Oil & Gas. A new folder for Natural Gas will be created within the Industry Research Folder. I'm wondering if there is any way for the rule to look into Oil & Gas folder and see that a folder with the name Natural Gas already exists, and then insert the file there. That way I don't end up with another Natural Gas folder higher up in the hierarchy.

Again, thank you so so very much for your help.....I am already lightyears ahead of where I was yesterday! You've given me hours of my life previously spent on filing back :)

Re: Multiple Spotlight Comments, Filing System?

PostPosted: Fri Jul 13, 2012 5:11 pm
by a_freyer
nphowery wrote:For example, if a file has two tags (tag1, tag2) attached, and if the folder for tag2 does not already exist, the rule starts all over again. So the tag1 folder ends up getting two copies: 1 when the rule runs the first time and 1 when it reruns to create the folder for tag2. Any thoughts would be much appreciated.


The "Sort into Subfolder" will create folders when they're needed - you don't have to create any folders. So, I'm not sure this is the problem, and the folder is only created once. Do either of the duplicated files have a color label of orange? You can see where the duplicate is coming by stopping hazel, adding a file and "Run Rules Now" incrementally, using the preview window to check what rules match what file.

Do any of these files being duplicated have the same tag more than once? The rule does not check for duplicate tags.

Alternately, in the last two rules, you can modify the options for the "Copy" and "Move" components to say "Do not move/copy" if a file already exists.

Other than that, I'd need an example file or directory structure to determine the problem.

nphowery wrote:Separately, I'm wondering if there is any way to run the rule on a whole tree of folders. For example, I have a folder called Industry Research. Inside this folder there are 35-45 folders. For example, one might be Oil & Gas. Inside Oil & Gas, there may be 4-7 more folders: Natural Gas, Exploration, etc.


I would use a "run rules on subfolder contents" rule. There are many examples of this in the forums. However, to prevent an infinite copying loop, you need to create something that tells Hazel which folders it should dive into. Perhaps set a color label for the folders you want it to dive into, or add a comment of "DO NOT SORT" or something similar.

Basically, we're looking for some pattern - some consistency - that we can tell use to tell Hazel what to dive into and what not to dive into.