Showing posts with label Mac. Show all posts
Showing posts with label Mac. Show all posts

Software to automate website screenshot capture

I needed a software that allowed me to capture screenshots of a web application I developed. The software should do it automatically (batch capture). This way it’d save me a lot of time.

How do I used to do that?
I visited each web page I wanted to take a screenshot. It took me about 1 hour to finish the work.

I posted a question at Super User as always: Software to automate website screenshot capture and got an answer suggesting that I use a combination of a URL fetcher + Selenium capability to take screenshots.

Well, I tried Selenium (.NET bindings selenium-dotnet-2.0rc3.zip ) to test its screenshot capture feature but it doesn’t seem to fit the job because it doesn’t allow you to configure screenshot properties as size (height x width). Moreover it doesn’t work well with Ajax (requires you to write a lot of code to check for the existence of Ajax calls, etc). This kills a screenshot that needs everything in place (I mean every DOM object should be part of the screenshot). I tried the 3 drivers available: Internet Explorer, Firefox and Chrome. Screenshots taken with Internet Explorer driver were close to what I expected.

This is a sample code I used based on the code taken from here:

using System;
using System.Drawing.Imaging;
using System.Text;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;

namespace SeleniumTest
{
    [TestFixture]
    public class SeleniumExample
    {
        private FirefoxDriver firefoxDriver;
    
        #region Setup

        [SetUp]
        public void Setup()
        {
            firefoxDriver = new FirefoxDriver();
        }

        #endregion

        #region Tests

        [Test]
        public void DisplayReport()
        {
            // Navigate
            firefoxDriver.Navigate().GoToUrl("http://localhost/FitnessCenter/Report/TotalPaymentsByPeriod");

            IWebElement startDate = firefoxDriver.FindElement(By.Name("StartDate"));
            
            startDate.Clear();
            startDate.SendKeys("January 2011");

            IWebElement generate = firefoxDriver.FindElement(By.Id("Generate"));
            generate.Click();

            var wait = new WebDriverWait(firefoxDriver, TimeSpan.FromSeconds(5));
            wait.Until(driver => driver.FindElement(By.Id("Map")));

            SaveScreenShot(firefoxDriver.Title);
        }

        /// <summary>
        /// Saves a screenshot of the current error page
        /// </summary>
        public void SaveScreenShot(string fileName)
        {
            // Get the screenshot
            Screenshot screenshot = firefoxDriver.GetScreenshot();

            // Build up our filename
            StringBuilder filename = new StringBuilder(fileName);
            filename.Append("-");
            filename.Append(DateTime.Now.ToString("yyyy-MM-dd HH_mm_ss"));
            filename.Append(".png");

            // Save the image
            screenshot.SaveAsFile(filename.ToString(), ImageFormat.Png);
        }

        #endregion

        #region TearDown

        [TearDown]
        public void FixtureTearDown()
        {
            if (firefoxDriver != null) firefoxDriver.Close();
        }

        #endregion
    }
}

Indeed, Selenium is powerful for what it does, that is, helping you automate browser interactions while you test your code. It even allows you to take a screenshot let’s say when something goes wrong (a test fail for example). That’s great and that’s what it does best. It’s a choice for every operating system since it’s an API that can be programmed against.

Paparazzi! beautiful application iconWhat I needed was something more specialized to take screenshots. A software that allows me to configure screenshot properties. The good news is that I managed to find such piece of software and it’s called Paparazzi! - a very suggestive name by the way. One drawback is that it’s only available for Mac OS. As one would expect, it uses Safari browser engine behind the curtains to capture the screenshots. Paparazzi! has minor bugs but it gets the job done. It doesn’t have documentation. I had a hard time trying to make it work. It has batch capture capability but no docs explaining how to do it. So I hope this post will shed some light…

The following lines describe what I did to achieve my objective with Paparazzi!:

1 - Created a list of URLs I’d like to take screenshots of. Like this (one URL per line):

http://192.168.1.106/FitnessCenter/Account/ChangeCulture?lang=en&returnUrl=%2FFitnessCenter%2F
http://192.168.1.106/FitnessCenter/Student
http://192.168.1.106/FitnessCenter/Student/Create
http://192.168.1.106/FitnessCenter/Student/Edit/79
http://192.168.1.106/FitnessCenter/Student/Details/79
http://192.168.1.106/FitnessCenter/Student/Delete/79
http://192.168.1.106/FitnessCenter/Anamnesis
http://192.168.1.106/FitnessCenter/Anamnesis/Create
http://192.168.1.106/FitnessCenter/Anamnesis/Edit/79
http://192.168.1.106/FitnessCenter/Anamnesis/Details/79

.
.
.

2 - Open Paparazzi! and click the Window menu => Batch capture (really difficult to find this option Disappointed smile ):

Paparazzi! difficult to find Batch Capture menu optionPicture 1 - Paparazzi! difficult to find Batch Capture menu option

3 - Drag and drop a text file .txt (the file that contains the URLs) to the Batch Capture window:

Paparazzi! Batch Capture window surfacePicture 2 - Paparazzi! Batch Capture window surface

Here is where I think I found a limitation and it’s by design. This should definitely not happen IMHO. If you try to add a file clicking on ( + button), Paparazzi won’t let you select a text file. The only way I got it working was selecting the .txt file and then drag and dropping the file to the Batch Capture window.

4 - Configure screenshot properties by clicking the list button (see mouse cursor above it):

Paparazzi! screenshot process basic configurationsPicture 3 - Paparazzi! screenshot process basic configurations

You can define the screenshot size. There are pre-defined values for standard screen resolutions. It allows you to define new presets.

You can also delay the capture to wait the page finish loading, etc.

There are a set of configurations available related to the batch capture functionality. To access these configurations, go to Paparazzi! menu and select Preferences:

Paparazzi! Preferences… menu optionPicture 4 - Paparazzi! Preferences… menu option

The first configuration worth mentioning the Default Filename Format available in the General section:

Paparazzi! General preferences sectionPicture 5 - Paparazzi! General preferences section

Above I’m defining this format:

%t = page title
%Y = year
%m = month
%d = day
%H = hour
%M = minute
%S = second

The example in the picture is pretty clear… Smile

Another set of configurations is available in the Batch capture section:

Paparazzi! Batch Capture preferences sectionPicture 6 - Paparazzi! Batch Capture preferences section

Here you can choose where to save the screenshots as well as the type of the images.

After configuring the batch capture session, it’s the gran finale time...

5 - Click the Play button, go take a coffee and relax while the computer does the job for you Fingers crossed.

Paparazzi! Batch Capture in actionPicture 7 - Paparazzi! Batch Capture in action

Hope you have found this post interesting and that it’s useful to help in documenting a little bit of this small but really powerful application.

Pointing up Now I get all the screenshots in less than 1 minute!

References
Paparazzi!
http://derailer.org/paparazzi/

Productivity and happiness going from 4 to 8 GB RAM

This post tries to illustrate the productivity improvements you get when you go from 4 GB to 8 GB RAM.

I bought a Mac mini last year and when I started using it to do software development, data started to be processed very very slow… I ordered mini with “just” 4 GB RAM. My assumption that I’d develop only Mac software wasn’t true because now I know that I can’t live without Windows development. This way I have to use a virtual machine/VM (Windows 7) to install Visual Studio, database servers and everything else. That requires a lot of memory as you may know already.

Situation before and after memory upgrade

Mac OS Win VM Comment Feeling
Before 3 GB 1 GB This is crazy. I know. Necessity rules. Steaming mad
After 4 GB 4GB This is what a software developer needs today. Open-mouthed smile

There’s nothing better than images to illustrate my situation before and after the memory upgrade. Pictures can tell thousands words… Seeing is believing!

Before memory upgrade

Mac OS Activity Monitor  ( before memory upgrade ) Screenshot 1 - Mac OS Activity Monitor  ( before memory upgrade )

Parallels Desktop with Windows 7 virtual machine - Process Explorer ( before memory upgrade ) Screenshot 2 - Parallels Desktop with Windows 7 virtual machine
Process Explorer ( before memory upgrade )

Parallels Desktop with Windows 7 virtual machine - System Information ( before memory upgrade ) Screenshot 3 - Parallels Desktop with Windows 7 virtual machine
System Information ( before memory upgrade )

After memory upgrade

Mac OS Activity Monitor ( after memory upgrade ) Screenshot 4 - Mac OS Activity Monitor ( after memory upgrade )

Parallels Desktop with Windows 7 virtual machine - Process Explorer ( after memory upgrade ) Screenshot 5 - Parallels Desktop with Windows 7 virtual machine
Process Explorer ( after memory upgrade )

Parallels Desktop with Windows 7 virtual machine - System Information ( after memory upgrade ) Screenshot 6 - Parallels Desktop with Windows 7 virtual machine
System Information ( after memory upgrade )

Analysis and Points to take into account
1 - In both Activity Monitors (Screenshot 1 and Screenshot 4) you can see in the pie chart that the sum of memory (3.75 GB and 7.75 GB) is always 250 MB bellow the total installed memory. This is because Mac mini shares its RAM with the video card.

2 - I do not turn off the computer, that is, I put the computer to Sleep (Mac OS term for what we call Hibernate in Windows). When the computer comes back from sleep its memory isn’t completely empty. These screenshots were taken while the computer was in the process of sleeping/waking for a few days and hence the values of Wired, Active, Inactive memory tend to stay high even after waking the computer.

3 - The number of open apps is for sure different but I can guarantee that I have much more apps open after the upgrade, for example: two Visual Studios (desenv.exe) in Screenshot 5 while I had only 1 VS opened in Screenshot 2. To make it even more clear we just have to compare the Totals section of Win 7 System Information. Before I had 53 processes and after 75 (Screenshot 3 and Screenshot 6). An increase of 41.50%.

4 - Despite the values for Page outs and Swap used, after the upgrade I change screens very very fast. So these values do not scary me anymore.

5 - After upgrading Parallels Desktop 6 to its latest release (Build 6.0.12090 / Revision 660720; May 26, 2011) I noted a better memory management regarding the virtual machine. Now Page outs and Swap used are in MBs as shown in Screenshot 7:

Mac OS Activity Monitor after Parallels Desktop upgradeScreenshot 7 - Mac OS Activity Monitor after Parallels Desktop upgrade

Conclusion
Comparing the data shown above, it’s clear that RAM upgrade plays a big role when it comes to developer productivity and happiness.

Now I can say that I have a responsive computer and that means a lot in my day to day work.

Developer: get 8 GB RAM if you can afford it. It’s the bare minimum in 2011. You’ll be happy. No stress… If you can afford and your hardware supports 16 GB RAM, go for it and you’ll have no RAM headaches for a long long period.

Manager or whoever pays the bill: give a descent computer to your developers with at least 8 GB RAM! No excuses… RAM is so cheap nowadays that I don’t understand how can a lot of developers out there work with less than the necessary amount of RAM.

Note 1: Windows processes and memory information come from Process Explorer by Sysinternals. It’s way better and more powerful than Windows default Task Manager.

Note 2: To better understand memory information in Mac OS, refer to this article by Apple: Mac OS X: Reading system memory usage in Activity Monitor

Software to add Lyrics to MP3 files ID3 metadata

Take a look at the MP3 series. Probably you’ll find something interesting.

If you're like me, you also like to take a look at the lyrics of music that is currently playing in your computer or mobile device as the iPhone. I do it to learn a bit more of English since its not my main language and of course because I also want to sing along correctly. :)

The iPhone for example allows you to read the lyrics of the current song if the lyrics are present in the MP3 ID3 metadata container. This is pretty cool. If you already have lyrics embedded in your MP3 files you can see them while in a bus trip, waiting for a service, etc.

Every MP3 has a specific field (also know as frame) in its metadata to store lyrics information. It’s just a matter of filling this field with the correct lyrics. This is a hard work to do manually because you have to search for the lyrics and then copy/paste it in the right field. This sounds like a great thing to be done by software instead. Again, that’s what computers are for… save us time.

In iTunes (the media player/library software I use) for example, one would right-click a music file and then select the Get Info context menu option. Then you’d select the Lyrics tab and paste the lyrics in the white huge field making sure to click OK as seen in Figure 1 below:

Adding lyrics to an iTunes music file through the Lyrics tab
Figure 1 - Adding lyrics to an iTunes music file through the Lyrics tab

Some time ago I asked a question at SuperUser site: Software to add Lyrics to MP3 files ID3 metadata. It seems that there are a lot of people (3,356 to be precise as the time of this post) out there looking to accomplish what this post tries to clarify.

When I asked the question I was using Windows and I got good answers.

I also discovered other software by myself as MiniLyrics for Windows at that time. If you’re interested in MiniLyrics, here goes a small tutorial to save the lyrics to MP3 metadata!

MiniLyrics
Right click MiniLyrics icon in the system tray, choose Preferences and then select the Lyrics icon. Under the Save downloaded lyrics in: - select Save lyrics in mp3 file.

Other great feature MiniLyrics has is that while the music is playing the lyrics can be shown on your screen according to what is being sung, that is, the lyrics flows in your screen according to the music timing. Fantastic job from crintsoft people... :)

Besides saving the lyrics to MP3 metadata, there are lots of features and possibilities when it comes to lyrics in MiniLyrics software.

From the official site:

    MiniLyrics Display lyrics for your favorite music!

        * Lyrics plugin software for iTunes, Windows Media Player, MediaMonkey, Winamp, etc. You do not need to change the way you enjoy music.
        * Display scrolling lyrics, you can follow along with the artist and catch every word.
        * Automatically search and download lyrics.
        * Huge lyrics database, and it is expanding everyday.
        * Free Trial version that never expires.

Lyricator
Lyricator as suggested by merv is a fantastic/great/cool piece of software to go with MediaMonkey but it is having some problems currently as you can find in this thread.

I had to resort to other service while Lyricator is being repaired. I found other free software that does the job, but only on a Mac computer (that’s OK because I’ve switched to the Mac world). It's name is Get Lyrical.

Get Lyrical

Get Lyrical doing its job in the background
Figure 2 - Get Lyrical doing its job in the background

    Get Lyrical auto-magically add lyrics to songs in iTunes!

You can choose either a selection of tracks, or the current track. Or turn on "Active Tagging" to get lyrics for songs as you play them.

    You can also browse and edit the lyrics of your iTunes tracks right from Get Lyrical.

I highlighted in yellow above a powerful feature of Get Lyrical. You can even add lyrics to a selection of tracks at once. This is a batch processing feature really welcome when you want to add lyrics to an artist’s complete discography for example.

I’ve been using Get Lyrical for some time now and it is really competent in the job. I highly recommend it.

Installing PHP on Mac OS X Snow Leopard 10.6.5

Motivated by this question at StackOverflow: RegExp PHP get text between multiple span tags, I decided to help.

Recently I got a Mac mini. I still hadn’t played with PHP on Mac and to debug my answer to that question I needed a way to test the code. So I thought: why not also give PHP a try on Mac OS since its my main OS today? Oh, good idea, go learn something new… :D

The first thing I did obviously was recurring to Google and searching for something that could help me get there.

I hit a pretty good tutorial to enable PHP on Mac at About.com written by Angela Bradley that gets to the point: How to Install PHP on a Mac. Along the way I had to solve only one minor thing described in the caveat section at the end of this post.

You see that the title of this post has the word installing (well I thought I had to install it – that was my first reaction), but in fact it could be the word enabling because PHP is an integral part of Mac OS X Snow Leopard and we just need to enable it as you’ll see soon.

Here we go. Follow these steps:

1 - Enabling the Web Server
PHP works hand in hand with a webserver. Mac OS already comes with Apache web server and so we just need to enable it. To do so, open System Preferences in the Dock. Then click the 'Sharing' icon in the Internet & Network section. Check the ‘Web Sharing’ box.

Web Sharing option under the Sharing configuration in System Preferences
Figure 1 - Web Sharing option under the Sharing configuration in System Preferences

Now type this address in your browser: http://localhost/. You should get a message that reads: It works!

2 - Enabling PHP
PHP also comes bundled in Mac OS, but it’s disabled by default. To enable it we need to edit a hidden system file located in this path: /private/etc/apache2/httpd.conf.

I used BBEdit text editor to edit such a file (note that I marked the box Show hidden items in the screenshot below):

Editing a hidden file with BBEdit
Figure 2 - Editing the hidden system file httpd.conf with BBEdit

Now within that file search for:

libexec/apache2/libphp5.so

Delete the character # in the start of the line so that that entire line should now read:

LoadModule php5_module          libexec/apache2/libphp5.so

Save the file.

3 - Testing the installation
There’s nothing better to test the PHP installation than using its own information. To accomplish this, write a one liner simple .php file named test.php with this content:

<?php phpinfo() ?>

Place this file inside your personal website folder. Mine is located in this path:

/Users/leniel/Sites/test.php

Now let’s test this page by typing its address in the browser:

http://192.168.1.103/~leniel/test.php

As you see, the address points to my personal website as seen in Figure 1.

When you run this simple .php page you should get something like this:

Testing PHP installation with its own configuration’s information
Figure 3 - Testing PHP installation with its own configuration’s information

If your PHP installation is OK, the test page will display PHP's information. If it displays the page code, you need to restart the Apache server.

You can restart Apache by entering the following in Terminal:

sudo apachectl restart

Try to reload the page again. Everything should work.

Well done!. Now you can play with PHP on your Mac computer and write some neat codez. :)

Caveat
When I tried to restart Apache server I got the following error:

ulimit: open files: cannot modify limit: Invalid argument

I resorted to this solution: Mac OS X 10.6.5 broke my apachectl

Useful tips/tricks about everything Mac

This post is where I’ll maintain useful things that I usually do in my day to day while using the computer and that I find nice to know about. They can save you some mouse clicks and most important: save you time.

As time passes by, this page will grow. :)

Adobe Acrobat

How to select only the text of a column of a table in a PDF file?

shift+option and select the text with the mouse.

iTunes

How to go to Current Song playing in iTunes?

command+L

or

You can right click the time bar and select Go to Current Song context menu option.


How to Delete duplicate songs from iTunes?

option+delete and select Keep File


How to delete Album’s embedded artwork from all tracks at once?

Select all tracks from the album. Right click over anyone of them and select the Get Info menu option. Now check the checkbox on the left side of the Artwork field (see screenshot below). Click OK and voila, iTunes will delete the artwork embedded in each file so that you can add a new/bigger/better artwork. This way you avoid having duplicate artwork making iTunes show the only one you want.

Make iTunes delete Album Artwork from all files at once


How to create a playlist using a Finder folder?

Creating an iTunes playlist from a Finder folderSelect the folder in Finder and drag it to iTunes icon in the dock. iTunes icon will blink. Wait a second or two. iTunes will be the active window (I consider iTunes is already open in the background before you perform this operation). Keep holding the mouse button. Now drag the folder to the Playlist section in iTunes left bar and release the mouse. As you see in the picture, I’m dragging and dropping a folder called My MP3 folder to iTunes PLAYLISTS section. When iTunes recognizes that you want to create a playlist from a folder it’ll highlight its left bar. This let’s you know that it’s time to release the mouse button and drop the folder there.

Mac OS

How to open a docked application at startup time/login?

Right click the app icon in the dock and select Options –> Open at Login.


How to search anything in your Mac from anywhere?

command+space This will bring Spotlight.


How to put Mac to sleep?

option+command+eject


How to go to any folder in Finder by its address/path (like Windows Explorer address bar)?

Right click Finder icon in the dock and select Go to Folder. Type or paste the folder path and click Go.

Finder Go to the folder dialog window


Added on 5/14/2011

How to copy the full path of a file or folder in Finder (really useful in software development)?

Use this fantastic Copy Full Path automator service workflow by Marcus Barnes. Read his post for more info.

Mac OS Finder with Copy Full Path Automator service

Learn more about Automator in this post: Automate tasks in Mac OS with Automator


How to show hidden files in Finder?

In Terminal type:

defaults write com.apple.finder AppleShowAllFiles TRUE

killall Finder


Added on 5/24/2011

How to open a terminal command window starting from the current folder you have open in Finder?

Use cdto. macoscdtologo Download it here.

cdto is a small app that opens a Terminal.app window cd'd to the front most finder window. It’s designed (including it's icon) to be placed in the Finder window's toolbar as shown below (mouse cursor is over it):

Mac OS cdto App Icon in Finder Toolbar

Add Songs to iTunes Playlist with Automator

Last time I showed you how to Automate tasks in Mac OS with Automator. I used Automator to create a simple workflow that helps moving MP3 files to iTunes folder. Check that here.

Now I have another task to Automator.

This is the description of what I want to accomplish or the problem description if you prefer:

I often download some free legal MP3 files from the internet for evaluation, more specifically from Indie Rock Cafe (great great site by the way :D - check it out if you like Indie Rock music). I use IndieRockCafe mainly to discover bands that I’ve never heard about. It’s being a great experience so far. I’ve come to know some really good bands that, else I would never hear a song of theirs.

To download those MP3s I use DownThemAll that is a really nice piece of software that works beautifully with Firefox. I wrote about DownThemAll in Automate the download of a list of URLs/links. Although I didn’t write how to download only MP3 files with DownThemAll, this post gives you an idea about the purpose of DownThemAll. I’ll write about how to download only specific kind of files (MP3 in this case) using DownThemAll, but that’s another post. Probably I’ll detail this download process I’m mentioning here.

As I was telling you, I often do the same task, that is, I go to IndieRockCafe, click on DownThemAll icon in my Firefox toolbar and tada, the download of IndieRockCafe’s recently added MP3s just start. DownThemAll will download only page links that point to MP3 files saving these MP3 in a single folder called IndieRockCafe.

After the download I used to select all the files within that folder and drag and drop them inside an iTunes playlist called IndieRockCafe. iTunes is wise enough to tell me that some files are already part of the playlist and gives me the option to skip them adding only new files into that playlist. Doing so I always have a fresh playlist with the latest files of IndieRockCafe. It works, but it has a lot of manual steps.

Yesterday I thought: the above steps are a perfect fit to be automated with Automator.

Let’s create a workflow:

1 - Go to the Applications folder and select Automator.

2 - You’ll be presented with the following screen to choose a template for your workflow. Select Folder Action as the template.

Types of templates available to create an Automator workflow (Folder Action)Figure 1 - Types of templates available to create an Automator workflow (Folder Action)

3 - In Folder Action receives folders and files added to, select the folder you want. In my case it is the IndieRockCafe folder.

4 - Now select Music in Library list and then select Import Files into iTunes under the Actions list. Drag this action to the workflow area in the right.

5 - Select Existing playlist and the playlist you want the files to go to. As I wrote above I already have a Playlist called IndieRockCafe inside iTunes. So I selected it.

6 - Go to the File menu and select Save. Give the workflow an appropriate name, e.g. IndieRockCafe.

The following screenshot shows the Folder Action workflow configured:

IndieRockCafe.workflow configured according to the six steps described above
Figure 2 - IndieRockCafe.workflow configured according to the six steps described above

7 - Now that the workflow is created, there’s a last step required to orchestrate things: go to the IndieRockCafe folder and right-click it. Select Services > Folder Actions Setup… Make sure you attach the IndieRockCafe workflow to this folder as shown in Figure 3:

Attaching IndieRockCafe.workflow in Folder Actions Setup
Figure 3 - Attaching IndieRockCafe.workflow in Folder Actions Setup

Make sure you click the Enable Folder Actions checkbox too:

Enabling Folder Actions and turning IndieRockCafe.workflow ON for the IndieRockCafe folder
Figure 4 - Enabling Folder Actions and turning IndieRockCafe.workflow ON for the IndieRockCafe folder

… and we’re done! As you see this is totally life saver.

Every new MP3 that gets added in my IndieRockCafe folder through DownThemAll or that I manually place in this folder will be automatically added in IndieRockCafe playlist.

Task successfully automated!

I’m a music lover and I hope you can take advantage of it too.

Important
DownThemAll creates file segments ( *.dtapart files ) while downloading. DownThemAll splits the file into several parts and then downloads each segment of the file individually, which gives you better speed from servers, especially those that choose to limit your download speed. This behavior will cause the workflow created above to fail because iTunes won’t recognize those parted files when trying to import them. To solve this problem, do the following:

In Firefox Tools menu choose More dTa Tools and then select Preferences.

In tab Advanced and under Temporary files choose a directory to store those dtapart files. See screenshot below to have an idea:

Using a temporary folder to store DownThemAll file parts or segmentsFigure 5 - Using a temporary folder to store DownThemAll file parts or segments

Doing the above, DownThemAll will store those partial files in a separate folder. When it finishes downloading a file it will join its parts and then will move that file to the IndieRockCafe folder I specified in the workflow. Now iTunes will import the MP3.

Note
Folder action workflows are saved in
/Users/YourUserName/Library/Workflows/Applications/Folder Actions

Download
You can download this workflow at:
https://sites.google.com/site/leniel/blog/IndieRockCafe.workflow.zip

Automate tasks in Mac OS with Automator

This one is about an incredible application that comes with Mac OS X. Its name is Automator.

Jesus Christ, this is a life saver app!

This is the description of Automator:Automator Apple Mac OS application icon

With Automator, you can accomplish time-consuming, repetitive manual tasks quickly, efficiently, and effortlessly. Automator lets you skip the complex programming and scripting that is normally required to create automations. Instead, you assemble individual steps into a complete task by dragging these actions into an Automator workflow. Automator comes with a library of hundreds of actions. And with the Watch Me Do action, you can record an action — such as pressing a button or controlling an application without built-in Automator support — and replay it as an action in a workflow.

I have lots of MP3 files that I need to go through analyzing if I really want to keep them in my media library. During the last year I stored all those MP3 in a folder and such a folder is now 55.56 GB and contains 11840 files to be precise. That’s a lot of MP3! I keep postponing this open/listen to task but today I thought I’d start. That’s where Automator fits the job.

In this post I’ll show you how to create a simple workflow that helps moving the MP3 files to iTunes folder /Users/leniel/Music/iTunes/iTunes Media/Automatically Add to iTunes. The folder Automatically Add to iTunes is a special folder that iTunes keeps watching for new files added to it. When a file is added in this folder, iTunes automatically adds it to the media library using MP3 metadata to organize the library. When added files will reside in /Users/leniel/Music/iTunes/iTunes Media/Music.

Let’s create the workflow:

1 - Go to the Applications folder and select Automator.

2 - You’ll be presented with the following screen to choose a template for your workflow. Select Service as the template.

Types of templates available to create an Automator workflow
Figure 1 - Types of templates available to create an Automator workflow

3 - In Service receives selected, select audio files. “In” select Finder.

4 - Now select Files & Folders in Library list and then select Move Finder Items under the Actions list. Drag this action to the workflow area in the right.

5 - In Move Finder Items select the folder where you want the files to be moved to. You also have the option of showing the action when the workflow runs.

6 - Go to the File menu and select Save. Give it an appropriate name as Add to iTunes and you’re done.

The following screenshot shows the Service workflow configured:

Add to iTunes.workflow configured according to the six steps described above 
Figure 2 - Add to iTunes.workflow configured according to the six steps described above

Now, let’s use this service workflow. To do this, go to Finder and open any folder that contains audio files such as MP3. Right click the MP3 file and voila. Now there’s an extra context menu option called Add to iTunes. What a marvelous thing.

Add to iTunes context menu option in Finder when right clicking MP3 file(s)
Figure 3 - Add to iTunes context menu option in Finder when right clicking MP3 file(s)

What happens when Add to iTunes is clicked? The workflow we created will be executed and the selected file(s) will be moved to the folder specified in the workflow, in this case /Users/leniel/Music/iTunes/iTunes Media/Automatically Add to iTunes.

As you see this is totally life saver.

I can play the MP3 in iTunes and if I decide that I want to keep it in my media library I just have to select Add to iTunes.

The possibilities with Automator are endless given the amount of options in its Library and Actions lists and workflow template types.

I hope you could get an idea of what Automator can do.

Updated on 12/16/2010

If you make a slight change in step 3 above you can have this workflow add not only audio files but even entire folders to iTunes and better yet, iTunes will ask if you want to replace existing files so that you don’t end up with duplicate files in your iTunes library. This is great.

So what do you have to do? Instead of audio files, select files or folders. Just this. Save the workflow. Now right click over any folder in Finder and you’ll see that you get a new menu option under Services called Add to iTunes.

Add to iTunes context menu option in Finder when right clicking a folderFigure 4 - Add to iTunes context menu option in Finder when right clicking a folder

Notes
Service workflows are saved in /Users/YourUserName/Library/Services.

In prior versions of Mac OS, there was an option to save the workflow as a plug-in. This was necessary so that you could have a context menu option (right-click) in Finder to run the workflow. I tried to go this way but this option isn’t available in Mac OS X 10.6.4. I realized that I had to create a Service workflow when I read this question at Apple’s Support site: No Automator plug-in in 10.6?

Download
You can download this workflow at:
https://sites.google.com/site/leniel/blog/AddtoiTunes.workflow.zip

References
Automator - Your Personal Automation Assistant

Automator - Learn by example

Automator at Apple’s Mac OS – All Applications and Utilities

Automator article at Wikipedia