Applescript folder names based on filename

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

Moderator: Mr_Noodle

Applescript folder names based on filename Tue Dec 30, 2008 8:40 am • by jbw
Hello folks. (new chap here!) :)
I've just stumbled upon Hazel and reckon it's a fantastic app however having searched this board I can't seem to find how to do something using applescript.

I want to take the name of a file hazel is currently working with 'Tv Show - S01E05' and create a set of substrings which can then be used as a path. i.e. Tv Show/Season 01/
I'd then check if the path already exists, if is does just move the file else create the path based on the substrings and then move the file.

I know a little about coding and although I've never used applescript I'm willing to get my hands dirty. How do I get the name of the current file Hazel is working with?
Also if there is any Hazel applescript support docs out there I'd really appreciate a link as I can't find any.

ta,
jbw
jbw
 
Posts: 2
Joined: Tue Dec 30, 2008 8:11 am

This can be done without AppleScript. Check the help for "match patterns".

What you can do is specify a pattern and specify custom tokens to match parts of the string. Since you know a little coding, you may know about regular expressions. If so, it's like using capture groups.

You can then use the "Sort into subfolder" action, dropping in the custom tokens to generate the name of the folder(s).

In your case, the pattern would be something like:

(show name) - S(season)E(episode)

with the custom tokens specified in parentheses. The show name could be any set of characters while season and episode would match numbers.

In any case, post here if you need any more help with this.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Applescript folder names based on filename Fri Jan 02, 2009 7:40 am • by jbw
Thanks for the help Mr_Noodle - that works a treat.

Cheers,
jbw
jbw
 
Posts: 2
Joined: Tue Dec 30, 2008 8:11 am

I'd like to do something similar, but with documents related to upcoming events. The document would be named based on the date that the event will be. for example, the event would be on january 20th, 2009. the file would be called: 012009.doc

When the document is emailed to me, i'd like to be able to save it to my "sort" folder located on my desktop, and have it sent to "~/Documents/Events/2009/January/"

I can't seem to figure out how to tell hazel to take a file named mmddyy.doc and translate that into yyyy/mm/

does this make sense?
n8white
 
Posts: 3
Joined: Tue Jan 13, 2009 3:00 am

You can match the file with the following pattern:

(month)(year)

where (month) is a custom token which itself matches two numerical digits and (year) is another custom token that matches 4 numerical digits.

You can then do "Sort into subfolders" with a pattern like:

(year) > (month)

where > is the folder separator (looks more like a triangle in the interface). Now, there's a slight problem in that Hazel can't translate a numerical month into the textual representation since when it matched it, it was interpreted just as a sequence of characters and has no notion that that number represents a month. But if you are ok with having ".../2009/01" then the above should work.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

ahhh, this makes sense. thanks a lot!

(by the way, the help documentation is very good)
n8white
 
Posts: 3
Joined: Tue Jan 13, 2009 3:00 am


Return to Support