Skip to content

Instantly share code, notes, and snippets.

@anilnatha
Last active August 29, 2015 14:04
Show Gist options
  • Save anilnatha/077e96b37dc72e060c27 to your computer and use it in GitHub Desktop.
Save anilnatha/077e96b37dc72e060c27 to your computer and use it in GitHub Desktop.
This AppleScript makes it easier to save screenshots to your clipboard than by using Apple's built-in keyboard shortcuts that do the same. I find Apple's keyboard shortcuts difficult to remember, which is why I created this script.
(*
Author: Anil Natha
Description: This applescript captures a screenshot and puts it into your clipboard. This AppleScript provides the user with three screen capture options, "Desktop", "Window", and "Selection".
If "Desktop" is chosen, it simply takes a screenshot of the currently selected desktop (this distinction is important for computers with multiple monitors).
If "Window" is chosen, the user can choose which window they wish to capture a screenshot of.
If "Selection" is chosen, the user can choose an area that should be used to capture a screenshot of.
Installation:
If you want this script accessible to all users of a machine:
Store this script at the following location of your OS X disk, /Libary/Scripts
If you want this script accessbile to only your user account on a machine:
Store this script at the following location, where '~' is the path to your user folder: "~/Libary/Scripts"
Known Issues/Limitations:
1. Once this script is executed, there is no way to "cancel" it. You must select an option. Unfortunately due to a limitation by Apple, Button List objects can only contain a max of three items, so I was unable to add a "cancel" button.
Recommendations:
1. While this script is useful on its own, I personally use FastScripts to provide very easy access to all of the scripts housed in the scripts folder in my user account (~/Library/Scripts). By using FastScripts you can not only execute scripts via the OS X Menu Bar, but it allows you to map a keyboard shortcut to your individual scripts to quickly trigger them. Unfortunately, FastScripts isn't free, but it is very cheap. Once FastScripts is setup, I simply mapped the keyboard shortcut, COMMAND + SHIFT + C to easily capture screenshots.
2. Whether you use FastScripts or not, one of the ways I keep my scripts organzed is bycreating folders in my 'Scripts' folder and grouping similarly themed scripts. Within FastScripts, this provides the extra benefit of submenus for scripts, with each submenu being a folder in your Scripts folder. You can also prepend your scripts filenames with "01)", "02)" to change the order in which they appear in FastScripts (this is only useful to fastscripts), if you do not do this, your scripts will be alphabetically ordered.
*)
-- prompt user for type of screenshot they would like to take
set myButtonList to {"Desktop", "Window", "Selected Area"}
try
set response to button returned of (display dialog "Take screenshot of..." buttons {item 1 of myButtonList, item 2 of myButtonList, item 3 of myButtonList})
if response = item 1 of myButtonList then
--process the creation of a screenshot of the desktop
set options to "-c"
else if response = item 2 of myButtonList then
--process the creation of a screenshot of a selected window
set options to "-Woc"
else if response = item 3 of myButtonList then
--process the creation of a screenshot of a selected area
set options to "-sc"
end if
end try
-- capture screenshot and copy to clipboard
do shell script "screencapture " & options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment