Automated for the People…

Wednesday, August 13th, 2008 | Work

…in which I talk about my recent experiments with Applescript and Automator, and probably bore you to tears.

So, in case you’ve never met me, I am the kind of person who likes to have things my way and will go to great lengths to customize things to be as close to my idea of perfect as possible. I would say I border on obsessive sometimes when it comes to attempting to achieve that perfection, but that would be a lie. There is no bordering, I’m all the way in. I’ve taken up residence in my obsessive compulsive need for things to function in the best possible manner.

To this effect, I’ve learned a lot about how Automator and Applescript work in the Mac OS X environment. I have to admit, I think Automator is one of the reasons I am starting to prefer Mac over PC. The fact that I can create miniature applications (applets) to do the things that, in my opinion, I need to do is invaluable to my pathological nature. Automator allows me to call forth commands and scripts from almost anywhere within the Mac environment and combine them into free running programs. It really is a great system.

Until recently, I had a free-standing application that would synchronize several different items with my Motorola Q through the Mac. It would automatically upload contacts, calendar items, photos, and music. Several factors have resulted in my abandoning that software. First off, with the University’s adoption of the Microsoft Exchange mail system, contacts and calendars are synchronized wirelessly on demand. Additionally, I found that I never really viewed photos on the phone. And finally, with my upgrade to OS X 10.5, I would have had to pay an additional $25 to upgrade to a Leopard compatible version of the software. I just didn’t see that it was worth the price, and system resources, just to move some music occasionally. Having previously purchased a pair of bluetooth stereo headphones, however, I really want to take advantage of the fact that my phone can play music. That, combined with the fact that I have over 20,000 songs in my iTunes library made me really lament the loss of that software. I decided there must be a way I can facilitate this process at no cost. First, I started surfing the web looking for a free alternative. Finding nothing, I turned to automator, which I’ve used in the past for smaller tasks, but never something of the complexity that this has turned out to be (links to the actions and downloads I used are at the bottom of this post).

I found, in Automator, that there is a command that can read a list of tracks in a specified iTunes playlist. How handy is that? So I chose the smart playlist I had created previously for my Q and called in that data. I then passed that data on to a file copy command which would copy (not move) all the files discovered in the playlist to a location of my choosing. I had discovered my solution with only two Automator actions. As of 5:00 yesterday, I was happy with that. This morning, however, after having played a custom HeroScape map and then tweaked it after everyone left, I decided I could tweak my script to be better and more efficient.

Having failed to find a way to mount my Q as a drive on the computer, I am relegated to pulling out the memory card and use the card reader built in to my monitor (I honestly never thought I’d use that) to mount the music folder. Since I was already physically taking the card out and inserting it into the computer, I figured there had to be a way to save myself from having to click to start the applet. After some searching online, which actually resulted in several methods of triggering an action on mount. I decided upon installing a Preference Pane (another nice customization option for Mac OS X, modular system preferences), that simply watches for events, and performs other events in response. So I told the Do Something When (the preference pane) to watch for my SD Card to be inserted, and respond by running the applet. It worked flawlessly. I found that I could also tell DSW to watch for an application to quit. So I told it to watch for my applet to finish and then unmount the drive as a response. I no longer had to touch the computer at all to copy files to the card. Each step was getting more efficient, but thin I hit a snag.

My card is a 1gb card, and I was telling it to copy 128mb of music to it every time I tested the system. Turns out, there was no mechanism in my applet to remove the old files, so the SD card was getting more and more full, and finally failed to run the applet because there was no more room. I had to modify the system. I found that there was an Automator action to move files to the trash, so now, before copying files to the card, it first moved all the files in the music folder on the card to the trash, theoretically making space. Unfortunately, it was moving the tracks to the Trash folder on the card and leaving them there, so I wasn’t actually gaining any free space, only moving stuff around.

I spent a good little while trying to find a way to empty the Trash on the SD card alone (since sometimes I actually do go back and check the trash on my computer). Short of some pretty specific Unix commands, there was no way to do it, and since I was trying to make this applet adjustable (in case any of my variable change later on) I needed to figure out something different. I finally stumbled up on an Automator action that simple deletes files rather than moving them to the trash, and I’m okay with that. I was trying to avoid downloading any third party actions, so that my applet would be as self contained as possible, but I just can’t find a way around this, at present. At any rate, I now had the files deleting correctly, the new files copying, and then the SD card dismounting. I finally decided that a nice alert as to its completion would be nice, so I added a Growl action at the end that pops up and informs me that its completed and dismounted.

All in all, its a really nice process that I may not use nearly as often as would be merited by the amount of effort that went into creating the system, but what I think is more important, is what I learned from it. I know more about Automator and Applescript than I did before. This is how I learn, its how I’ve always learned. I find some lame project that doesn’t amount to anything of real value, but the processes can be applied to more important things down the line.

To that same effect, I’ve once again, surprised myself with my ability to decipher web code and rebuild it to work the way I need it to.

Yesterday I found that I needed to build a specialized page for the new CVAD web site but once it was built, it just wasn’t working the way it was supposed to. After some fine manipulating of the core programming, I was able to get my page to work just fine. It was a foray into completely foreign territory for me, but everything seems to have worked out perfectly, so I’m proud of my progress. I know that I often don’t credit myself with my adaptability or ability to learn, but in moments like that, I’m always surprised at how adept I really am at absorbing and reworking things that I have so little experience with. That’s definitely a skill that could get me work in other, more lucrative positions (damn you shirt.woot, why are you in St. Louis?).

If you want to build an Automator Applet similar to mine, or even use some of the concepts I’ve talked about, here is what I had to download to make it work:

To delete files directly from Automator, I installed the action Delete Files.

The Preference Pane I used to watch for events was Do Something When.

And of course, who can do anything fun without Growl.

And finally, if you really want to see how it all came together, here’s the workflow, but be forewarned, there are a lot of defined variables in here so you would have to reconfigure almost ever action to point to the folders and playlists that you have specific to your system: iTunes Playlist Exporter.

Tags: , , , , ,


Something is wrong.
Instagram token error.



August 2008
« Jul   Sep »