Moving a file to a folder specified by a token

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

Moderator: Mr_Noodle

I have read previous posts indicating that you cannot sort into a subfolder using a wildcard. However, I'm trying to do something slightly different, which I cannot figure out how to do / if it can be done.

A (not so) brief background is that I scan in virtually all of my bills, receipts, etc. I save the files with names that are an abbreviation that is easy to type, in an "Incoming Scans" folder. I then need each file to be renamed with a more descriptive "proper" name, and then moved to the proper place in a large folder tree that keeps all the scanned documents. As an example, I might scan in an American Express bill and save it as "amex 2012.1004", then it is renamed to "American Express 2012.1004" and moved to /Users/nl/ScannedDocuments/Bills/CreditCards/AmericanExpress." I know there are other ways to organize this, but this is how I do it and it works for me.

THe sheer number of different things I scan makes it impractical to have a separate Hazel rule for each thing that is regularly scanned, and I have already explored using patterns to handle the process and that approach doesn't really apply (there's an earlier question and response from Mr. Noodle on this where we discussed that). Plus, I cannot really remember all the various abbreviations and so wanted a way to print out a list of my abbreviations and what they refer to.

What I hit upon is to write a script that runs off a data file that lists valid abbreviations as a regex, the "proper" name to rename the file to, and the location to move the file to after renaming. The data file is actually written as a Markdown table so it can easily be converted to a nice format for viewing/printing, so this would work well for me. The script returns two tokens to Hazel: the name to use in renaming the file, and the target folder for the file to be moved into.

The problem is that as far as I have been able to figure out, the move file action does not accept a token, and therefore I cannot actually perform the move. I could move the file to the root of the scanned documents folder and use a sort into subfolder, which does take a token, but as the file might have to go arbitrarily deep into the folder tree and as far as I can tell, sort into subfolder can only go one level deep at a time, so that won't work. To make matters worse, I handle the finances for several elderly family members, and each set of documents has its own folder tree to go into.

I was hoping there was a way to use Hazel to do the move. If there isn't I can fall back to just using a shell script to actually move the file, and maybe that's the only way to accomplish this. (I haven't yet experimented to see if a token can be passed into a shell script...). I figured I'd ask before giving up....

Sorry this was so long - I included a lot of detail in case there is a better way to have approached this in the first place, as I am open to that if I have gone about those in the wrong way.

Thanks!
nl
nlippman
 
Posts: 12
Joined: Sun Jun 09, 2013 9:31 pm

Sort into subfolder can go as deep as you want. Use the separator (which looks like a triangle pointing right) to denote different levels of folders.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks. I was aware of that (the list separator). I was hoping to be able to directly move the file to the target folder as determine programmatically. Instead, I can move it to the highest level folder under which any other target sits, and them sort to the proper subfolder.

nl
nlippman
 
Posts: 12
Joined: Sun Jun 09, 2013 9:31 pm

Sorry, another area of confusion.

I know that the separate token is a rightward pointing arrow symbol. When creating a pattern for the subfolder, you can click on the icon for that token.

Is the token "active" in a path: for instance, if I sort into a subfolder with the name a▸b▸c, does this successfully move the file into folder c under b under a, or do you actually have to create a pattern using the token itself? If the latter, then you still cannot move to an arbitrary level of subfolders without knowing the depth in advance (unless I am missing something).

Otherwise, I would take the target subfolder, e.g. "a/b/c" and with "a/b/c".replace("/', "▸") create a string that could be passed into the action.

nl
nlippman
 
Posts: 12
Joined: Sun Jun 09, 2013 9:31 pm

Nope: I tried it. Do a sort into subfolders with the subfolder being the text a▸b causes a new folder with the name "a▸b" to be created, not to move the file into "a/b".

How would you create a rule to move a file into a subfolder that is arbitrarily deep - eg, how can I return a token from an applescript with the location into which a file should be moved, and have it moved there? (other than just using a script to do the move, which I guess is the only way to do it.)
nlippman
 
Posts: 12
Joined: Sun Jun 09, 2013 9:31 pm

I tested it again here and it works as expected. If you have a pattern a▸b, it files it in a folder b under folder a. Make sure you are using the ▸ token, and not entering that character. If you still can't get it working, I suggest emailing support with an exported version of your rule if you still can't get it working.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support

cron