An Applescript to Move Screenshots From the Desktop

September 30, 2009

This Applescript is a folder action I wrote that moves screenshots taken with Mac OS X from my Desktop to a designated screenshots folder.  Setting it up requires that you enable folder actions and then assign this script as a folder action to the Desktop folder.

I’m sure variations of this script have been written a million times over, but it was a minor success for me as I practice and learn Applescript.

If you found this page because you were looking for a snippet of code, there are some examples that you can take from the code below:
  • how to check for a running process
  • how to register an application with Growl and enable Growl notifications
  • how to check for a Uniform Type Identifier (UTI) instead of checking for a given file type or file extension

Here’s the code:

on adding folder items to this_folder after receiving these_items

    -- Check to see if Growl is running
    tell application "System Events" to set growl_running to exists application process "GrowlHelperApp"

    -- Set the location of the new "screenshots folder"
    set screenshot_folder to "Ken's Macbook:Users:kenclark:Pictures:Screenshots:"

    -- Register these notifications with Growl
    if (growl_running) then
        tell application "GrowlHelperApp"
            set the all_notifications_list to {"File Move Complete", "Error"}
            set the enabled_notifications_list to {"File Move Complete", "Error"}
            register as application "Ken's Applescripts" all notifications all_notifications_list default notifications enabled_notifications_list icon of application "Script Editor"
        end tell
    end if

    tell application "Finder"
        repeat with x from 1 to the count of these_items
            set this_item to item x of these_items
            set item_name to name of this_item
            tell application "System Events" to set type_id to type identifier of this_item
            try
                if (type_id is "public.png") and (item_name starts with "Screen shot") then
                    move this_item to screenshot_folder
                    if (growl_running) then
                        tell application "GrowlHelperApp"
                            notify with name "File Move Complete" title "File Move Complete" description item_name & " was successfully moved." application name "Ken's Applescripts"
                        end tell
                    end if
                end if
            on error error_message number error_number
                tell application "GrowlHelperApp"
                    notify with name "Error" title "File move failed" description error_message & "
" & error_number application name "Growl Applescript Test"
                end tell
            end try
        end repeat
    end tell
end adding folder items to
  • homeshire

    just a quick line to let you know I appreciate your posts on scripting. I am in the same boat, and I love finding resources from others who are trying to learn and master scripting too.

  • Ken Clark

    Thanks! I’m having a good time learning Applescript, and I intend to write about my experiences learning it as I go. I’ve found getting my mind wrapped around a project — even when its a small one — really pushes the learning process forward.

  • Connor Mulcahey

    Hey I understand you wrote the over a year ago but would there be any reason that it wouldn’t work anymore? After proofreading it all I could find was that perhaps it needed to have “Macintosh HD” added to the part where it assigns the screen shot folder and I also capitalized the second s in “Screen Shot” when it says if (item_name starts with “Screen shot”) because that is what they are named as now. Yet unfortunately it still doesn’t work. :(  

    Likely no fault of your own but rather just an update to OS X or Growl or something.

    Any ideas??

  • http://kenclark.me Ken Clark

    Not sure. I haven’t run this script under Lion as I am using Hazel now to move screenshots from the desktop. However, you might want to create a test image (“test.png”) and hardcode that name into the script and then try putting that on the desktop. If it works / doesn’t work with test.png you will have more info on where the script is breaking.

Previous post:

Next post: