Condition matches a space but renames file with a return

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

Moderator: Mr_Noodle

I am running Hazel 4.0.5 . I have a series of rules that file credit card receipts. The goal of this particular rule is to rename the receipt with the date of transaction and the Payee and auto-file it into the appropriate folder

In the first IF section of the rule, I have several lines that check for commonly used Payee names. At the very end of this section, I simply check for the existence of a space. All of these lines use "Contents" "Contain Match" and assign to Payee.

In the rename section, I rename to "Credit Card Name (Payee) IncrementalNumber.Extension"

If the series of Ifs match a common payee, then the file is renamed with that payee. Otherwise, since most receipts would contain a space of some sort and the last IF checks for a space, then if Hazel cannot find a common payee name, then the section of the renamed file that would normally contain a payee name surrounded by a left and right parentheses, I should (and most times do just get a left and right parentheses in the file name. For example, if Hazel could not find a common payee name then the renamed file might be something like "2016-09-17 Chase Visa ( ) 354.pdf"

Most of the time this works fine. When it doesn't work, Hazel seems to rename the file with a (space + carriage return) so the end result would be something like:

"2016-09-17 Chase Visa (
) 354.pdf"

So when you view the file name on the Mac, in the above example you would see just

"2016-09-17 Chase Visa (

You have to click on the file name after the right parentheses and remove the "hard carriage return" so that the file name displays all on one line.

Something that makes this problem even worse is that when it creates this goofy filename with the "hard carriage return" in it, it is creating it in a folder that is actually a Microsoft OneDrive folder and those filenames with the "hard carriage returns" in them do not sync until the offending character is removed.

So with all of the above said, I am looking for some answers.

1. Is there a better way to do what I am trying to do?
2. When I am matching known payee names and find none, I would rather rename the file with something like (no-match) or something but I don't see any way to do that. It is my understanding that the Payee variable is just going to be the contents of the match and that I don't have any way of changing it to some default value. That is why I just checked for a space which should be pretty common
3. Sometimes on one given receipt, I can scan it several times and some of the time, it will work just fine with a nice pair of parentheses but 9 times out of 10, that same receipt will somehow be renamed with a "hard carriage return"

Any ideas would be appreciated.

Thanks,

Rod
rodqmiller
 
Posts: 2
Joined: Sat Sep 17, 2016 12:27 pm

If there is a carriage return there, then chances are it's coming from the source. Note that a space in a pattern (when matching contents) will match any amount of whitespace (including carriage returns).

Instead of matching space, if you don't care about the existence of the payee, why not structure the conditions to make that part optional? You can use nested conditions to do that: https://www.noodlesoft.com/kb/how-to-cr ... onditions/
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks for your response. My rule already has nested conditions in it but my goal is to set the PAYEE token to a default value of something like "Unknown" if it is not matched to a list of known payees

I already have a nested condition with several lines where I have a custom Text "token" called Payee where each line checks to see if Payee matches a particular name.

Here is a simplified version of my rule
___________________________________
If ALL of the following conditions are met
Extension is PDF

If ANY of the following conditions are met for THE CURRENT FILE OR FOLDER
Contents contain match PAYEE
Contents contain match PAYEE
Contents contain match PAYEE

If ANY of the following conditions are met for THE CURRENT FILE OR FOLDER
Contents contain visa

If ANY of the following conditions are met for THE CURRENT FILE OR FOLDER
Contents contain 1234567

In the "Do the Following to the matched file or folder" section, I rename the file with Visa (PAYEE) extension
________________________________

If I understand Hazel correctly, it appears that in a rule, the entire top section (if x of the following conditions are met), nested conditions or not are all "IF" statements and the bottom section (Do the following to the matched file or folder) are "DO" statements of some sort. But I don't yet see where I could check for a certain value in PAYEE and if that value is not there, then set that value to something else like "Unknown"

I've been wanting to play with Applescript and am wondering if this it might be required for this situation. This seems like a simple task so I'm pretty sure I'm just missing something.
rodqmiller
 
Posts: 2
Joined: Sat Sep 17, 2016 12:27 pm

You can split it up into two rules. If "Payee" isn't matched, have the next rule rename it with the default name. Otherwise, a script may be needed.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support