How can I rename screenshot files added to my Screenshot folder?

I used Cocktail to specify that screenshots are saved to a folder called "Screenshots" on my Mac. I use an app called "Hazel" to watch that folder and to automatically run an AppleScript that shows a dialog box asking if I want to rename the screenshot.

Here is the dialog box that pops up automatically:

Dialog box asking whether I'd like to rename a screenshot

Here is a screenshot of Hazel, with my "Name it" rule: Hazel screenshot

Clicking the edit (pencil) button in that window shows you the conditions under which the rule will run. As you can see, Hazel will run the AppleScript if the file is an image, added today, whose comment does NOT contain the word "Hazel." Since newly-made screenshots do not have comments with the word "Hazel" in them, these are the right conditions. (When the script runs, it adds a comment with the word "Hazel" in it to the file.) Hazel rule conditions

Here is my AppleScript.

tell application "System Events"
    set the_apps to every process whose frontmost is true
    set the_app to item 1 of the_apps
    set the_app_name to name of the_app
    set old_name to name of theFile
    set the_choice to display dialog "If you want to rename this file, do it" buttons {"Rename", "No thanks"} default button "Rename" default answer old_name
end tell

if the button returned of the_choice is "Rename" then
    set the_date_string to do shell script "date '+%Y.%m.%d'"
    tell application "Finder"
        set the comment of theFile to "Name changed with Hazel"
        set the_name to text returned of the_choice
        set cleaned_name to change " " into "_" in the_name
        set cleaned_name to the_date_string & "_" & cleaned_name
        if (characters 12 thru 13 of cleaned_name as string) is "wm" then
            move theFile to (POSIX file "/Users/cboyce/Dropbox/Screenshots/Webmaster Screenshots")
        else
            move theFile to (POSIX file "/Users/cboyce/Dropbox/Screenshots/Renamed Screenshots")
        end if
        set the name of theFile to cleaned_name & ".png"
    end tell
end if
tell application the_app_name to activate

The first part of the script records the name of the frontmost app at the time of the screenshot's creation. It also has the "Display Dialog" step.

The second part of the script renames the screenshot and moves it to a "Renamed Screenshots" folder. If I put "wm" at the beginning of the file's new name, the script puts the renamed screenshot into a special "Webmaster Screenshots" folder. The script also replaces spaces with underscores, but you would not have to include that part. Notice also that the script sets the comment of the screenshot to "Name changed with Hazel." You of course can make your own conditions but this works for me.

You will have to change the username in the script, in the two lines that start with "move theFile." Replace "cboyce" (my username) with whatever yours is. If you're not sure what yours is, find the Users folder at the top level of your Mac's hard drive, open that up, and look for the folder with the house icon. The name of that folder is the username. Actually, you have to change the entire path. I'm saving my renamed screenshots into folders stored in my Dropbox folder but you of course can put them where you like. So change the path in those "move theFile" lines to point to YOUR folders.

Hazel is commercial software but you can use it in Demo mode for free. Demo mode allows you to watch only a single folder, which in your case is all you need. You can download Hazel from Noodlesoft.com.


You might try using the app Grab. It comes with your system software and is stored in the Utilities folder. You can use Grab to take a screenshot, then click on menu item File and choose Save. This will allow you to name the file and select folder to store screen shot.