Custom token repeating - can it be done?

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Custom token repeating - can it be done? Sat Mar 16, 2013 5:26 pm • by Cassady
Hello all,

I've finally progressed to the point where I have been able to start playing around with a few more complex rules, including the use of custom tokens.

Thanks in particular, to this workflow iro NoteTakerHD: http://technosavvy.org/2012/09/02/autom ... ith-hazel/

Now I've hit a bit of a dead-end, and would appreciate some thoughts.

What I want to do:

[Sort into subfolders] from a variety of files that have been downloaded automatically from my iPad.

The [filename] has been set in a specific manner in the iPad app, to include "tags" as the last string of the filename. It is this "tag" that I am using as the [custom token] to [sort into subfolders].

The first part of the [filename] is allocated by me - and this is where things get tricky.

The [filename] string is as follows:

(Variable filename)_NoteTakerHD_Date & Time_TAG.pdf

I have set up the rule using custom icons as follows:

http://dl.dropbox.com/u/48750317/Screen ... 7%20PM.png
Code: Select all
abc_NoteTakerHD_•File Year-•File Month-•File Date-•Hour-•Min-•Sec_•TAG

The TAG is in reference to how the file is "tagged" in NoteTakerHD on the iPad.
I have created similarly named [subfolders] - and have successfully managed to get Hazel to [move], [label] and [sort] the files into each [subfolder], with surprisingly little effort.

But here's the problem.

The above obviously only works if the (Variable filename) is only one word. Or alternatively, I name the file (in NoteTakerHD on the iPad) without using any spaces. If I use spaces in naming the file in NoteTakerHD - the filename comes out with (underscores) _ placed where the spaces were. Which obviously started messing with the Custom Token setup.

Now I could do that (have no spaces)- but would prefer not to, since I have plenty of files in the NoteTakerHD app, and it makes things easier to find, if I can keep the filename's sensible.

So for instance - I might have a filename simply called (Meeting), and have it tagged as "Project" - which the above rule would then send to my (Project) sub-folder. But I would hardly do that.
I would rather name the file (Site Meeting), tagged "Project" - or (Aspen Site Meeting), tagged "Project".
Which would be converted to: "Site_Meeting_NoteTakerHD_...." and "Aspen_Site_Meeting_NoteTakerHD_..."

So I then tried the following:

http://dl.dropbox.com/u/48750317/Screen ... 9%20PM.png
http://dl.dropbox.com/u/48750317/Screen ... 0%20PM.png

I "nested" the [Condition] as follows:
Code: Select all
If (any) of the following conditions are met:
(Name) (matches) abc_NoteTakerHD_•File Year-•File Month-•File Date-•Hour-•Min-•Sec_•TAG
(or)
(Name) (matches) abc%abc_NoteTakerHD_•File Year-•File Month-•File Date-•Hour-•Min-•Sec_•TAG
(or)
(Name) (matches) abc%abc%abc_NoteTakerHD_•File Year-•File Month-•File Date-•Hour-•Min-•Sec_•TAG
(Then)...


This actually looked like it would work...

I figured it would allow for all 3 eventualities: "Meeting_NoteTakerHD_..." [or] "Site.Meeting_NoteTakerHD_..." [or] "Aspen.Site.Meeting_NoteTakerHD_..."

I could then simply use a period "." [or any other symbol, even the _ ] in naming the file, where there would have been a space - and in so doing, still make it easy to read/find/identity files when I was working in the NoteTakerHD app.

However... just as I thought I was in the clear....

Whereas the (FILENAME) problem was resolved, since the [nested conditions] actually worked, a new problem arose with the [•TAG].

The "second" [•TAG] in the nested condition appears to be automatically set by Hazel to become [•TAG 1], and the "third" [•TAG] automatically becomes [•TAG 2]... I cannot seem to change this.

Which means, when it comes to the [Rule] part, I am presented with the following:
http://dl.dropbox.com/u/48750317/Screen ... 6%20PM.png
Code: Select all
[Move] to folder
[Set color label]
[Sort into subfolder] with patern: •Tag •Tag 1 •Tag 2

Naturally, I don't need to select all of them - but I have tried all of them in varying combinations...

The upswing of this is as follows:

Assume all 3 (filename) eventualities are present in my (watched folder), I have my (target folder) "/NoteTakerHD Files" and a (sub-folder) entitled "/Project" in my (target folder):
Code: Select all
(Watched folder):
[1] "Meeting_NoteTakerHD_Date & Time_Project"   
[2] "Site.Meeting_NoteTakerHD_Date & Time_Project"
[3] "Aspen.Site.Meeting_NoteTakerHD_Date & Time_Project"

(Target sub-folder):
/NoteTakerHD Files/Project


If I ONLY use [•TAG] in the Rule - then [1] "Meeting_NoteTakerHD_Date & Time_Project" is moved into (sub-folder) "/Project", and [2] and [3] are left in the parent-target folder (/NoteTakerHD files).
This is because [•TAG] only runs the 1st nested condition, presumably.

If, as in the last screengrab, I use [•TAG] [•TAG 1] [•TAG2] in the Rule, then Hazel does the following:

[1] "Meeting_NoteTakerHD_Date & Time_Project" INTO "/NoteTakerHD files/Project" (my creation)
[2] "Site.Meeting_NoteTakerHD_Date & Time_Project" INTO "/NoteTakeHD/ProjectProject" (HAZEL created)
[3] "Aspen.Site.Meeting_NoteTakerHD_Date & Time_Project" INTO "/NoteTakerHD/ProjectProjectProject" (HAZEL created)

I understand why Hazel is doing this.
The use of [•TAG] [•TAG1] [•TAG 2] is causing it to create a Folder by allocating the new folder's filename from the repeated use of the TAG descriptor in the original file.

I hope anyone that has actually read this far, has managed to follow what I've tried to demonstrate.

My simple question is as follows:

Can I get HAZEL to recognise the [•TAG] as being the same one - in other words, also treat [•TAG] as an (Or), like it does the (Variable Filenames) - and if this is not possible, how should I re-write my rule?
All I want, is for me to not be concerned with using a 1,2,3 worded (filename) in the iPad app, and have Hazel move any of those to ONE sub-folder, named in terms of that filename's "tag"....

Should I simply bite the bullet, and create 3 separate rules?
I'm quite prepared to - just wanted to check that I wasn't missing something simple, and thereby contribute to my learning the rules etc...

Thanks again!
Cassady
 
Posts: 47
Joined: Wed Mar 06, 2013 4:34 pm

Re: Custom token repeating - can it be done? Sat Mar 16, 2013 5:42 pm • by Cassady
Oh, by the way - this is what the multiple rule screenshot looks like, and it works a charm. :D

http://dl.dropbox.com/u/48750317/Screen ... 5%20PM.png

So this certainly solves my conundrum, but as mentioned - first wanted to check whether or not I was missing some trick that would allow for an incorporated rule... :wink:
Cassady
 
Posts: 47
Joined: Wed Mar 06, 2013 4:34 pm

I just came here looking for a solution to a similar problem. I'd swear this worked before. I have a custom token for "year" set for the first four digits in the file name (so a file name that starts with 2013-01-24, gets 2013 set as the year token). I have a rule that had three separate matches, all of which used the same token. It stopped working at some point. Now when I try edit it, the second and third tokens get renamed year 1, year 2. It looks like selecting a token is not allowed in your match conditions, but I'd swear it used to work.

For now, I've set my sort into subfolder to use all three tokens butted up against each other with no spaces. If Havel is just processing a single file that meets one of the match criteria, that seems to work fine and it only uses the token actually in the match. On the other hand, if I copy several files into my to be processed folder, Hazel gets confused and creates new folders called 20122013, etc.
shovland42
 
Posts: 2
Joined: Sun Mar 17, 2013 5:21 pm

Re: Custom token repeating - can it be done? Mon Mar 18, 2013 5:11 am • by Cassady
shovland42 wrote:I just came here looking for a solution to a similar problem. I'd swear this worked before. I have a custom token for "year" set for the first four digits in the file name (so a file name that starts with 2013-01-24, gets 2013 set as the year token). I have a rule that had three separate matches, all of which used the same token. It stopped working at some point. Now when I try edit it, the second and third tokens get renamed year 1, year 2. It looks like selecting a token is not allowed in your match conditions, but I'd swear it used to work.

For now, I've set my sort into subfolder to use all three tokens butted up against each other with no spaces. If Havel is just processing a single file that meets one of the match criteria, that seems to work fine and it only uses the token actually in the match. On the other hand, if I copy several files into my to be processed folder, Hazel gets confused and creates new folders called 20122013, etc.


Thanks for the reply Shovland42 - I appreciate it. I never considered using the tokens like that without spaces - something to keep in mind. As it is, I had everything work well by setting up multiple rules, and that's probably the way to go. Still - it's very good to know I'm not the only one out there thinking along the same lines - hopefully this will also help out any others that might end up at the same spot...
Cassady
 
Posts: 47
Joined: Wed Mar 06, 2013 4:34 pm

Re: Custom token repeating - can it be done? Mon Mar 18, 2013 11:37 am • by a_freyer
Alright, I believe I understand what you're after. It that by using multiple rules you found a solution.

That said, I'll point out that based on your naming syntax, you should probably be using "anything" instead of "word" to match your tags. Hazel's custom tokens match the smallest possible group, so when you use "anything" followed by an underscore, you're going to match the tag strings.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Custom token repeating - can it be done? Mon Mar 18, 2013 12:29 pm • by Cassady
a_freyer wrote:Alright, I believe I understand what you're after. It that by using multiple rules you found a solution.

That said, I'll point out that based on your naming syntax, you should probably be using "anything" instead of "word" to match your tags. Hazel's custom tokens match the smallest possible group, so when you use "anything" followed by an underscore, you're going to match the tag strings.


Goodness, I never thought of that. Would "[anything/...]_NoteTakerHD_..." simply look at whatever came before the underscore before "NoteTakerHD" part, even if there are additional underscores in the preceding part? If so - then problem solved. I just presumed that with a 3-part filename containing underscores (or whatever symbols), would throw things out... Will definitely give it a go - since if it works, that will remove the need for the multiple rules, and is precisely why I popped up my query

Thanks for the help!
Cassady
 
Posts: 47
Joined: Wed Mar 06, 2013 4:34 pm

Re: Custom token repeating - can it be done? Mon Mar 18, 2013 12:32 pm • by a_freyer
If you have (anything)_ the (anything) will return anything before the FIRST underscore in the filename:


This is a test to show you what I mean_ok? returns "This is a test to show you what I mean"
This is_a test to show you what I mean_ok? returns "This is"
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Custom token repeating - can it be done? Mon Mar 18, 2013 12:49 pm • by Cassady
a_freyer wrote:If you have (anything)_ the (anything) will return anything before the FIRST underscore in the filename:


This is a test to show you what I mean_ok? returns "This is a test to show you what I mean"
This is_a test to show you what I mean_ok? returns "This is"


Ah - ok.

Apologies for what is no doubt to be an incredibly stoooopid question - but is "anything" only looking for the underscore, or any symbol?

In other words, if I use [anything] instead of [abc%], does:

This.is.a.test_ok return "this is a test" or "this", since it's counting "anything" written prior to the "."?

I am asking the above to get clarity on the underscore - if the underscore is treated differently by Hazel, then I could use [anything] but simply use any other symbol ( ". ") except the underscore, in separating the "variable filename".

However, if the underscore is simply treated as any other symbol, then [anything] might not work, since my naming pattern will still involve a variety of words, separated by symbols.
Cassady
 
Posts: 47
Joined: Wed Mar 06, 2013 4:34 pm

Re: Custom token repeating - can it be done? Mon Mar 18, 2013 12:52 pm • by a_freyer
For:

(anything)_(other matching stuffs)


This%is.a*test#to@show-you+what=I mean_ok? returns "This%is.a*test#to@show-you+what=I mean"
This%is_a*test#to@show-you+what=I mean_ok? returns "This%is"
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Custom token repeating - can it be done? Mon Mar 18, 2013 12:57 pm • by Cassady
a_freyer wrote:For:

(anything)_(other matching stuffs)


This%is.a*test#to@show-you+what=I mean_ok? returns "This%is.a*test#to@show-you+what=I mean"
This%is_a*test#to@show-you+what=I mean_ok? returns "This%is"


Good grief! That's a not-insignificant-point you've just made for me. Thank you! I use plenty of underscores in naming my files, as does NoteTakerHD by default, and [anything]'s relationship to the underscore makes things so much clearer now!
Cassady
 
Posts: 47
Joined: Wed Mar 06, 2013 4:34 pm

Re: Custom token repeating - can it be done? Mon Mar 18, 2013 1:06 pm • by a_freyer
To be clear, the underscore is not treated any differently by Hazel. Let me try to explain it this way. Hazel is looking to match your filename to a certain pattern. That's why you need to define your pattern.

So, lets say we have your filename:

(Variable filename)_NoteTakerHD_2013-03-18-08-51-00_TAG.pdf


What pattern can we use?

Lets write it out in text:

first the variable name,then an undersocre, then NoteTakerHD, then an underscore, then a year, then dash, then month, then dash, then day, then dash, then hour, the dash, then minute, then dash, then second, then underscore, then tag.

So, lets generalize further:

first some text,then an undersocre, then NoteTakerHD, then an underscore, then a four-digit number, then dash, then a two-digit number, then dash, then two-digit number, then dash, then two-digit number, the dash, then two-digit number, then dash, then two-digit number, then underscore, then some text.

Ok, now let's make that Hazel'ed:

(...)_NoteTakerHD_(1)(1)(1)(1)-(1)(1)-(1)(1)-(1)(1)-(1)(1)-(1)(1)_(...)

Ok, now let's take some of those groups and make them custom tokens (but with the same content)

(Variable Filename •)_NoteTakerHD_(year•)-(month•)-(day•)-(hour•)-(minute•)-(second•)_(Tags •)

Now, yes I know that you know how to do this, but it's important now to read that back and make sure that it makes sense to Hazel as a pattern.

Hazel will read that pattern like this:

Take the smallest group of characters at the start of the filename before the first underscore and call it (Variable Filename •)
Take the first four digits that appear after the text _NoteTakerHD_ and call that (Year •)
Take the first two digits that appear after a dash following four digits following _NoteTakerHD_ and call that (Month •)

... and so on.

Make sense?
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Custom token repeating - can it be done? Mon Mar 18, 2013 1:26 pm • by Cassady
a_freyer wrote:To be clear, the underscore is not treated any differently by Hazel. Let me try to explain it this way. Hazel is looking to match your filename to a certain pattern. That's why you need to define your pattern.

So, lets say we have your filename:

(Variable filename)_NoteTakerHD_2013-03-18-08-51-00_TAG.pdf


What pattern can we use?

Lets write it out in text:

first the variable name,then an undersocre, then NoteTakerHD, then an underscore, then a year, then dash, then month, then dash, then day, then dash, then hour, the dash, then minute, then dash, then second, then underscore, then tag.

So, lets generalize further:

first some text,then an undersocre, then NoteTakerHD, then an underscore, then a four-digit number, then dash, then a two-digit number, then dash, then two-digit number, then dash, then two-digit number, the dash, then two-digit number, then dash, then two-digit number, then underscore, then some text.

Ok, now let's make that Hazel'ed:

(...)_NoteTakerHD_(1)(1)(1)(1)-(1)(1)-(1)(1)-(1)(1)-(1)(1)-(1)(1)_(...)

Ok, now let's take some of those groups and make them custom tokens (but with the same content)

(Variable Filename •)_NoteTakerHD_(year•)-(month•)-(day•)-(hour•)-(minute•)-(second•)_(Tags •)

Now, yes I know that you know how to do this, but it's important now to read that back and make sure that it makes sense to Hazel as a pattern.

Hazel will read that pattern like this:

Take the smallest group of characters at the start of the filename before the first underscore and call it (Variable Filename •)
Take the first four digits that appear after the text _NoteTakerHD_ and call that (Year •)
Take the first two digits that appear after a dash following four digits following _NoteTakerHD_ and call that (Month •)

... and so on.

Make sense?


Thanks - makes sense. I'll play around a bit with the (variable filename) - and pop something up when I manage the consolidation.
Cassady
 
Posts: 47
Joined: Wed Mar 06, 2013 4:34 pm

As usual, thanks a_freyer for your help here.

To elaborate a bit, patterns can sometimes be ambiguous. When you specify a pattern, the matching system will try and interpret it in whatever way will make a match. The result is that what is captured by each token may differ depending on what is needed to make a match.

So, if you have a pattern like "(anything)_foo" and text like "abc_123_foo", if (anything) matches "abc", then the pattern as a whole won't match. If (anything) matches "abc_123", then the pattern as a whole does match so that is the value that is captured in this case. Things get more complicated when you have more tokens and such but the general idea stands.

And as pointed out, (anything) will match as little as possible. All of the other tokens will match as much as possible. The notion here is that if you are specific about what you want, you want all of it. Like if you want a number, you want the full string of contiguous digits, not just some arbitrary partial set of them. (anything), being by definition totally unspecific, is just there to pick up the stuff outside the more specific stuff, if that makes sense.
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Custom token repeating - can it be done? Mon Mar 18, 2013 3:54 pm • by Cassady
Mr_Noodle wrote:As usual, thanks a_freyer for your help here.

To elaborate a bit, patterns can sometimes be ambiguous. When you specify a pattern, the matching system will try and interpret it in whatever way will make a match. The result is that what is captured by each token may differ depending on what is needed to make a match.

So, if you have a pattern like "(anything)_foo" and text like "abc_123_foo", if (anything) matches "abc", then the pattern as a whole won't match. If (anything) matches "abc_123", then the pattern as a whole does match so that is the value that is captured in this case. Things get more complicated when you have more tokens and such but the general idea stands.

And as pointed out, (anything) will match as little as possible. All of the other tokens will match as much as possible. The notion here is that if you are specific about what you want, you want all of it. Like if you want a number, you want the full string of contiguous digits, not just some arbitrary partial set of them. (anything), being by definition totally unspecific, is just there to pick up the stuff outside the more specific stuff, if that makes sense.


Thanks Mr. Noodle - this has helped plenty!
Cassady
 
Posts: 47
Joined: Wed Mar 06, 2013 4:34 pm


Return to Support