Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.6: Rename screenshots with Automator and AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: Rename screenshots with Automator and AppleScript
Authored by: llee on Dec 07, '09 01:35:11PM
It's been a while since I thought about this, but whenever I take a screen shot I always think "One of these days, I'm going to start managing screen shot names again." Here's what I've decided to try. What I really want is to be prompted to name my screen shot whenever I take one. So I put together this AppleScript and attached it to the Desktop folder as a folder action. If I'm not satisfied with it after trying it for a while, I'll consider the matter further.
on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		set screenshot_name to (get displayed name of (item 1 of added_items))
	end tell
	if screenshot_name starts with "screen shot" then
		try
			tell application "Finder"
				set name_extension to (get name extension of (item 1 of added_items))
				set the folder_name to the name of this_folder
			end tell
			set the item_count to the number of items in the added_items
			set alert_message to "Folder Actions Alert:" & return & return
			set alert_message to alert_message & "A new screen shot exists in the " & the folder_name & "."
			repeat
				set the alert_message to (the alert_message & return & return & "You can enter a new name for it if you like..")
				display dialog the alert_message buttons {"OK", "Cancel"} default button 1 with icon 1 default answer "Enter new name here."
				set the new_item_name to ((text returned of the result) & "." & name_extension)
				if the new_item_name contains ":" then
					display dialog "A file or folder name cannot contain a colon (:), please rename." buttons {"Cancel", "OK"} default button 2
				else if the new_item_name contains "/" then
					display dialog "A file or folder name cannot contain a forward slash (/), please rename." buttons {"Cancel", "OK"} default button 2
				else
					repeat with i from 1 to (count added_items)
						my set_item_name((item i of added_items), new_item_name)
					end repeat
					exit repeat
				end if
			end repeat
		on error ther
			display dialog ther
		end try
	end if
end adding folder items to

on set_item_name(this_item, new_item_name)
	tell application "Finder"
		repeat
			set the parent_container_path to (the container of this_item) as text
			if not (exists item (the parent_container_path & new_item_name)) then
				try
					set the name of this_item to new_item_name
					set the error_message to error_message -- "The name is too long."					
					tell me to display dialog the error_message default answer new_item_name buttons {"Cancel", "OK"} default button 3
					copy the result as list to {new_item_name, button_pressed}
					my set_item_name(this_item, new_item_name)
				end try
				exit repeat
			else --the name already exists
				tell me to display dialog "This name is already taken, please rename." default answer new_item_name buttons {"Cancel", "OK"} default button 2
				copy the result as list to {new_item_name, button_pressed}
				my set_item_name(this_item, new_item_name)
				exit repeat
			end if
		end repeat
	end tell
end set_item_name
Edited on Dec 07, '09 01:39:45PM by llee


[ Reply to This | # ]
10.6: Rename screenshots with Automator and AppleScript
Authored by: mark hunte on Dec 08, '09 04:43:34PM
As a Quick example, using a hotkey app.
there is no need to change the name of the file after it has been created, You can set the name before you
do the screen capture.
The script below will ask for the folder you want to save to, the name of the captured file and delay to when the capture is taken.
I have set the format here as jpg.

As I said a quick example, no checking if file exist, and other stuff that could be added.


tell me to set thePath to (choose folder)
set thePath to (POSIX path of thePath)
set format to "jpg"
       set defAns to "." & format as string
tell me to display dialog thePath default answer defAns buttons {"Cancel", "OK "} default button 2
  copy the result as list to {text_returned, button_pressed}
tell me to (display dialog "set Delay" default answer 2 buttons {"Cancel", "OK "} default button 2)
  copy the result as list to {text_returned2, button_pressed2}
 set Delay_ to text_returned2 as number
 delay Delay_
set doit to do shell script ("screencapture   -t" & format & space & (POSIX path of thePath) & text_returned as string)
 
---
mh


[ Reply to This | # ]
10.6: Rename screenshots with Automator and AppleScript
Authored by: llee on Feb 01, '10 07:49:30AM
The only problem I see with that is that you have to replace or supplement the OS X default shortcuts with equivalents using either the same or different shortcuts that employ your script. (I know it's possible, I already do it with command-f.)The default screen shot shortcuts offer quite a bit of varied functionality, and I think it would be quite an exercise to duplicate it all just to employ a script. I think the folder action provides a better compromise.

[ Reply to This | # ]
10.6: Rename screenshots with Automator and AppleScript
Authored by: bcometa on Dec 10, '09 02:40:22PM

thanks llee, works great!



[ Reply to This | # ]