Screen shot (with addition of a hotkey) sent to folder "x"

I know nothing about applescripting, but thought this might be a good place to start.
How would one go about being able to create a script, which could be called via something like http://www.red-sweater.com/fastscripts/ (Fastscripts), to send any screenshot taken with (command + shift + option + 4) (for instance) to a specified folder on the desktop?

I take a lot of screenshots and would like a better way to organize them.

Someday in my dreams there will be an app that takes that folder and regularly uploads the contents to flickr… :slight_smile:

Any thoughts?

matthew

Model: imac intel
Browser: Firefox 2.0.0.1
Operating System: Mac OS X (10.4)

Hi Mathew,

What kind of names would you give the screenshot? For instance you might name it “picture_001.pdf” or use a date stamp “screenshot_01-07-2007.tiff”. You want preferably a name you can use to organize your files.

Then when you upload, you could duplicate the file with a new generic name that you can upload and replace some file. Or if you’re not replacing a file, you want a name you can use for uploading.

Mainly, you need a naming convention.

You can take interactive screenshots withsomething like:

do shell script “/usr/sbin/screencapture -i ~/Desktop/Screenshots/screenshot_001.pdf”

You need to think about how you want to name the files first.

gl,

Hi Artis

You can save this has an application:

property N : 0
set N to N + 1
set picPath to ((POSIX path of (path to desktop)) & "screenpic_" & N & ".png") as string
do shell script "screencapture " & quoted form of picPath


it should give you a re numbered screenshot everytime its run.
if you want to reset it back to 1 just open it up and re-compile the script then save again.
they are created on your desktop, should be easy enough for you to point it at a folder!!

kel, pidge 1 thanks.

Kel, for naming, numerical is enough, so long as they don’t conflict. I am doing this to keep a “scrapbook” of User Interface or Inspiring design I find. I will import some into iview and others into flickr, or some combination of the two. There will be other screenshots I’m not concerned about ending up in one folder or another, as they are for other purposes.

Pidge 1,
Thank you for your helpful script. I’d like to understand more how you came up with this. Where’s a good resource to decipher it? Also, the reason I used the command selection above is because I really prefer using the screen shot tool with the cross hairs so that I can choose the size I want, and not have to edit it later. Is there a dictionary I should be looking at to adapt your script? Also, at “path to desktop” can I just add a /folder to the end of that to create a place for images to land?

Thanks for your help,

Matthew

Hi Mathew,

You can find out how to use ‘screencapture’ in the terminal. Just type “screencapture”.

Here’s the script I was working on, but didn’t know what type of name you wanted to use.


property base_name : "Picture"
property the_ext : ".pdf" -- change this extension to your screenshot extension type
-- check for main folder
tell application "Finder"
	if exists folder "Screenshots" of desktop then
		set ss_folder to (folder "Screenshots" of desktop) as string
	else
		set ss_folder to ¬
			(make new folder at desktop with properties {name:"Screenshots"}) as string
	end if
end tell
set date_stamp to (current date) as string
set file_spec to (ss_folder & base_name & "_000") as file specification
set ref_num to (open for access file_spec with write permission)
set end_mark to (get eof ref_num)
write (date_stamp & return) to ref_num starting at (end_mark + 1)
close access ref_num
-- get index of last screenshot
tell application "Finder"
	set last_file to (name of last file of folder ss_folder whose name begins with base_name) as string
end tell
set last_index to (word 3 of last_file) as integer
-- create new name with new index
set new_index to text -3 thru -1 of ("00" & (last_index + 1))
set new_name to base_name & "_" & new_index & the_ext
set posix_path to POSIX path of (ss_folder & new_name)
-- take screenshot
say "use the space bar to switch modes"
do shell script "/usr/sbin/screencapture -i " & (quoted form of posix_path)

The space bar switches between cursor and window modes. You need to change the extension in the property at the top to the tye of extension your system uses. Mine is “.pdf”. The file “Picture_000” is a dummy file, but you can use it to get an estimate of when you took screenshots and with a script you could easily search for pictures you took at a certain date.

gl,

Hi Artis

I got this idea regarding the property from “Danny Goodmans” Applescripting Book you should get hold of that if you can. When i was reading the section about
persistent properties i knew i wanted to incorparate it into a script…

Somebody will probaly step in here and say “you shouldn’t do it that way it’s not reliable enough !!” or something along those lines…

I’m not 100% on this (could test it i suppose just lazy!) but if you add the -i flag like in kels it may prompt you to drag round an item or window etc…
you could always paas the “screen pic” onto an app like image events to crop it down i have one running like this on our server which takes a screenshort everyday!

Has for putting these in a folder, you will need to script the finder with that one, (make new folder with properties etc…) i won’t go into how you do that cause it is straight forwardish stuff and a very good place
for you to start to learn. Try searching on the forum!

Good Luck!

Guys, You should note that just changing the extension name may allow Preview.app to open the files, but they will not really be pdfs.
They will still be .png’s

This seems to be a common mistake people are making because apps like Preview.app are forgiving.

To change the type of file in screencapture you should use the -t option (-tfiletype.

Here are two scripts I wrote a while back to do just this type of thing. We do a lot of screen grabs at work and needed them.
Both are intended to use with hot keys and saves the files as jpegs

The first captures the whole screen (the main one I use.)

property the_count : 1
property you_folder : (path to documents folder from user domain) as string
property vid_g : "vid_grabs"
on run
	tell application "Finder"
		if not (exists folder vid_g of folder you_folder) then
			make new folder at documents folder with properties {name:vid_g}
		end if
	end tell
	set TheFolder to you_folder & vid_g & ":" as string
	
	set TheFolder to POSIX path of TheFolder
	set the_year to year of (current date) as string
	set the_month to month of (current date) as number
	set the_month to the_month as string
	
	set the_day to day of (current date) as number
	set the_day to the_day as string
	set the_hours to (current date) as string
	set the_hours to words 5 thru 6 of the_hours as string
	set the_name to "Screen_Grab_" & the_year & the_month & the_day & "_" & the_hours & "_"
	do shell script "screencapture -S -tjpeg  " & TheFolder & the_name & the_count & ".jpg"
	set the_count to the_count + 1
	
end run


The second offers interaction. (updated for frontmost app)

property the_count : 1
property you_folder : (path to documents folder from user domain) as string
property vid_g : "vid_grabs"
on run
	tell application "Finder"
		if not (exists folder vid_g of folder you_folder) then
			make new folder at documents folder with properties {name:vid_g}
		end if
		
		set TheFolder to you_folder & vid_g & ":" as string
		
		set TheFolder to POSIX path of TheFolder
	end tell
	tell application "System Events"
		
		set target_app to item 1 of (get name of processes whose frontmost is true)
		
	end tell
	tell application target_app
		display dialog "Capture Screen interactively, by selection or window" & return & return & ¬
			"Capture while holding CRTL key down - causes screen shot to go to clipboard" & return & ¬
			"space key   - toggle between mouse selection " & return & return & ¬
			"escape key  - cancels interactive screen shot" buttons {"Cancel", "OK"} default button 2
	end tell
	set TheFolder to POSIX path of TheFolder
	set the_year to year of (current date) as string
	set the_month to month of (current date) as number
	set the_month to the_month as string
	
	set the_day to day of (current date) as number
	set the_day to the_day as string
	set the_hours to (current date) as string
	set the_hours to words 5 thru 6 of the_hours as string
	set the_name to "Screen_Grab_" & the_year & the_month & the_day & "_" & the_hours & "_"
	do shell script "screencapture -i -tjpeg  " & TheFolder & the_name & the_count & ".jpg"
	set the_count to the_count + 1
end run


Hi Mark,

There are several places in my post where I wrote to change the extension to the type of extension of the screenshots on user’s computer. Note that you can change the default type of screenshots.

Thanks for the -t option information though. I didn’t know Apple added that.

gl,

Sorry I think I read to fast… and miss (skip :rolleyes: )bits. Bad habit.

Kel, et all,
Thanks for your help. This is freakin awesome! I love it.
I duplicated the script and changed the folder and img_prefix and have two folders set up.
One for user interface stuff and the other for inspirational design.

Sweet!

Over time, I’m sure I can see adapting this and growing it.
How cool would it be if you could add flickr data in a popup window and send it to flickr
all in one go!

For now I’ll use the flickr plugin for quicksilver :slight_smile:

Thanks again.

Now I might be addicted to the power of scripting… this is not good…