Tag Archives: automator

Print a Hierarchical List of Disk Contents

VFX companies often include paper printouts of a hard drive’s contents when they send material to/from Production, the DI, and other vendors. Occasionally, it’s useful for Editorial departments to do the same. Having a printout attached to a hard drive you’re sending out lets your vendor see exactly what’s on the drive without having to plug it in, and can be used to log a drive in or catalog it while it’s offline.

Strangely, there’s a lack of software available to do such a simple task as printing a directory listing. Searching through Google, I found a few applications for OSX that offered this functionality, but either the application wasn’t exaclty what I was looking for, or it added too many flourishes like icons and such.

So, I turned to the Terminal. Using a pattern I found in a forum on Unix.com, I modified the arguments and incorporated it into an Automator workflow (attached). This workflow displays a recursive list of directories (if you want only files or both files and directories see the bottom of this post), and is broken into the following steps:

  1. Asks for the root folder you’d like to make a listing from. This would usually be the root of your external hard drive.
  2. Asks how many levels of recursion you’d like.
    • Example: In one instance I was backing up P2 cards. I only needed to list the folder name of each P2 card I was including, and not the CONTENTS, VIDEO, VOICE, PROXY, ICON, and AUDIO folders that exist as subfolders of a P2 card’s root directory. So using this function with a recursion level of 2, my printout stopped processing directories after 2 levels of hierarchy.
  3. Runs the shell command:
find "$2" -type d -maxdepth $1 ! -name '.*' -print 2>/dev/null|awk '!/\.$/ {for (i=1;i<2  && i != 1 )d=5;printf("%"d"s","|")}print "---"$NF}'  FS='/'
  1. Saves a text file with the listing in the same directory you chose in Step 1, and then opens that file so you can browse and print it.

The output looks like this:

|      |---Warrior Back Up
|      |              |---Dailies by Tape
|      |              |              |---CT001
|      |              |              |---HI-8
|      |              |              |---VT001
|      |              |              |---VT002
|      |              |              |---VT003
|      |              |              |---VT004
|      |              |              |---VT005
|      |              |              |---VT006
|      |              |              |---VT007
|      |              |              |---VT008
|      |              |              |---VT009
|      |              |---P2 Backup
|      |              |        |---MISC
|      |              |        |---PRODUCTION
|      |              |        |---REHEARSAL FIGHTS
|      |              |        |---TESTS

Future Refinements

Suggestions welcome, but things I'm already thinking to add to this workflow later on are:

  1. An option to show files as well as folders. You can change this in the workflow yourself by changing "-type d" to "-type f" for a files-only listing, or remove "-type d" completely for both files and folders.
  2. A dialogue to ask if you want to print the listing automatically

Automating Avid Project Backups

REVISED 9/23/09: Rewrote for Leopard

The Importance of Backing Up

The most important part of an Avid project is, of course, the project directory. Media can be replaced, albeit tediously, but your project directory cannot. Therefore, it is not only important that you back up your project daily, but that you also take it with you when you leave for the night. Simply copying the project from one workspace to another is not sufficient, nor is just copying it to your local Avid drive. If a disk or two fails on the Unity and the only copy of the project you have is there, you’re probably screwed. If there’s a fire and both your Unity and your desktop Avid burn up, you’re definitely screwed. The number one rule of making backups is that the two copies must be geographically separated. I cannot stress that enough.

Thankfully, it’s easy and painless to do this, and you can automate it. It doesn’t matter whether you use a PC or Mac, you can automate it on either platform. But for the purposes of this tutorial, and since I’m pretty solidly in the Mac user base now, I like to use Automator and Growl (both Mac-only). To download my Automator script, click the link at the bottom of this post.

Automator

The process of creating an Automator workflow to back up your Avid project is fairly simple. The process I’ve chosen involves syncing the Avid project directory on the Unity to a copy of it on your Avid’s desktop, creating a zip file of the desktop copy, and then transferring that to a USB drive. It requires five actions, which are these:

  1. Run a Shell Script

    Don't forget to change this command to your own project directory and desktop folders!

    • This command runs the program rsync, with the arguments “-avP” to provide directory recursion (so it will copy all subdirectories of your project directory), copy almost everything while maintaining file attributes, and be verbose about what it’s doing (which is good if you run this command manually from the Terminal, but won’t have an affect in Automator). The command is as follows:
    • rsync -avP --delete --exclude "*.log" --exclude "~avid_remove*" --exclude ".DS_Store" --delete-excluded /Volumes/Project/YOUR_PROJECT /Users/YOUR_USER/Desktop
    • The “–delete” argument tells rsync to delete any files on your local directory that do not exist on the Unity. So if you delete a bin on the Unity, it will make sure that bin is removed from your local drive, too.
    • The “–exclude” arguments tell rsync NOT to back up any files that match *.log, ~avid_remove, or .DS_Store in their filenames
    • The –delete-excluded argument tells rsync to delete any files in your backup directory that do not exist in your project folder, including files that have been excluded above, if for some reason there are any in your backup directory
    • The reason I use rsync instead of just re-copying the entire Avid project folder to the desktop and overwriting yesterday’s copy is that when your project directory gets to be several GB in size, it is much quicker and just as thorough to copy only the files that have changed since your last backup. Otherwise you end up recopying a bunch of bins that haven’t changed since months ago, and that takes time.
  2. Get Specified Finder Items
    • Once rsync finishes, this command runs to tell Automator where your backup directory is.Get Finder Items (Leopard)
  3. Create Archive
    • This action takes your desktop Project directory, and creates a zip file out of it. You want to do this because bin files (.avb) are highly compressible, meaning that you can take your 2GB project directory and compress it down to a couple hundred MBs.
    • In the “Save as:” text box, you can see I’m telling Automator that I want my zip file to be named with a variable for today’s date, such as “Warrior.90922.zip” and that I want it saved to the Desktop.

    Create Archive (Leopard)

    My Automator variable that inserts today's date. Rearrange the parts of the date however you like. I choose this method so Finder sorts my backups chronologically.

  4. Copy Finder Items
    • This action takes your newly minted zip file and copies it to your flash drive.
    • N.B. Plug your flash drive in before running this workflow. If you don’t, Automator will fail, but if you do then you can leave and come back in 10 minutes to a fully backed up project already on your flash drive.
    • Copy to Flash Drive (Leopard)

  5. Show Growl Notification (optional)
    • This step allows you to display a Growl notification once the backup has completed. I find this useful because I can go make some tea while Automator is running and see at a glance when I come back if it’s done yet. Growl will also make a sound when it displays the notification, so you can grab your flash drive the instant it’s done and go home. Growl is a separate application you have to install, though, so there is a bit of extra prep you need to do before this action will be available inside Automator.

      Growl (Leopard)

      Make your Growl notification "Sticky" if you want the notification to remain on screen until you click on it.

And that’s it. After Automator finishes, you’ll have a backup copy of your project on both your local Avid drive, and your flash drive. You should then take your flash drive home with you every night, so that your backup copies are in separate places. I also keep an archive of every zip file I make on an external hard drive. Most of the time you won’t need this, but sometimes it’s useful to be able to go back a few days or months in your project’s history.

Attachments: