Need help with Hazel

I frequently have to download student assignments through Blackboard (our online learning system). I have a Hazel script set up that watches the download folder and moves to the appropriate class folder. I would like to rename each file (fairly long string) with just the last name of the student and name of the assignment. I would also like to delete the accompanying text file that comes with each Word file.
I wish I had an example, but I can’t download ‘old’ assignments and we don’t start classes until Monday!
I’ve tinkered a bit and have David Sparks videocast on Hazel, but it’s a bit beyond my skill set.

Where is the name of the student and the assignment? If the zip archive has the assignment name and the file name contains the student name somewhere that should be manageable. My university uses a custom Moodle install or I’d play with a dummy course and see if I could whip something up!

I cleared one of the 'attempts from last year to provide an illustration.

It does download into a folder. 09%20PM

This is my current Hazel ‘rule’

Is 533/534 the ID of the class, the student, or the assignment?

533 is the class ID first semester. 534 is second semester.

Can’t you just truncate the filename so that everything from _attempt onward is deleted? Then split on _ and swap the order of the two lines, then join.

Huh? :slight_smile: sounds good if I knew how to do that in Hazel.

1 Like

I think you may need 3 rules:

Rule [1] Delete text files:

Rule [2] Match Word documents for class ID 534:

This assumes that files are predictably named “534-” plus some other descriptors so you may need to change based on the actual file names.

I used the name matches rule to create a custom token that could be re-used to name the file:

Then use the custom token to rename the file:

Rule [3]: Repeat Rule 2 but change so that it matches on class ID 533.

This doesn’t fully meet your criteria for the renaming, but it will capture the first 8 (you can change to increase or decrease) characters of the filename so you have a decent descriptor of the file.

Hope that helps!

3 Likes

Wow!! Thanks for taking the time!

Glad to be of help! :grinning:

Here’s how you’d do it in Python:

s = str(sys.argv[1])

n = s.split("_attempt",1)[0].split("_")

print str(n[1]+"_"+n[0])+".docx"

and in Hazel:

1 Like

@Doc5506 , that is a very fine diagram.

glad you liked it! hope it was helpful. :grinning: