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.
blog comments powered by Disqus

Previous post:

Next post: