I want to take a screenshot of a window on a mac.
I'm currently using shift + cmd + 4 then space then mouse click.
The process is very awkward, you got to do it in that order or you'll have to repeat it again..
I'm wanting a simple keyboard shortcut to do what shift + cmd + 3.
I want to use as simple a shortcut for taking a screenshot of a window.
Is it possible?
Best Answer
Here's my solution, which I named Window-Snapshot, base on a very simple AppleScript, either saved as an application from within the Script Editor and or used as part of an Automator Service with keyboard shortcut assigned. Although as a Service it uses the third-party utility used in the Window-Snapshot AppleScript application's one* mouse-click solution detailed below.
As an AppleScript Application
This can be setup to be either a two mouse-click solution (the default) or a one* mouse-click solution.
As a two mouse-click solution the AppleScript it's saved as an application, I saved it as Window-Snapshot in Applications, and then placed it in the Dock by dragging and dropping the application bundle onto the Dock where I wanted it to be.
delay
command as a timer to allow positioning the mouse pointer before it times out and automatically takes the snapshot used in the one* mouse-click solution. By itself the two mouse-click solution is the easiest solution presented herein.As a one* mouse-click solution the AppleScript is saved as an application and the third party utility CLICLICK is added to the application bundle and corresponding code is uncommented in the script.
delay
command to allow time in positioning the mouse pointer anywhere over the target window to be captured and doesn't matter whether or not the window is the top-most window, when the seconddelay
command times out whichever window the mouse is over that's the one captured in the snapshot. The capture can be aborted by pressing the esc key before the seconddelay
command times out.As an Automator Service with keyboard shortcut
As Automator Service it's created using the ApplesScript code, modified slightly, and a keyboard shortcut is assigned to the Service in: System Preferences > Keyboard Shortcuts > Services
Window-Snapshot AppleScript Code
0.25
second value,delay 0.25
, on the firstdelay
command, this short delay is necessary as there needs to be a delay between the twokeystroke
commands. If using the one* mouse-click solution the seconddelay
command needs to be something more realistic. Set a value that allows you the time necessary to move the mouse over the target window before the delay command expires, e.g.1.5
etc.Creating the Window-Snapshot Application
Open Script Editor (or AppleScript Editor if applicable).
Copy and paste the Window-Snapshot AppleScript Code, from above, into the Untitled document window and then press Compile.
Press ⌘S to save and set the File Format: to Application saving it in the Applications folder.
Give the Window-Snapshot application bundle a custom icon. I used an icon of a camera found at Find Icons and used this one in particular clicking the 'Download ICNS' button. I opened the downloaded "scanners_cameras.icns" file in Preview and copied it and then pasted it into the Get Info sheet of the Window-Snapshot.app by first selecting the little icon in the upper left corner of the Window-Snapshot Info sheet. (In Applications select the Window-Snapshot.app and press: ⌘I)
Now drag and drop the Window-Snapshot application bundle from the Applications folder onto the Dock where you would like it to be.
It's now ready to be used, click the Window-Snapshot Dock Tile and then click the target window to be captured.
Screen Shot yyyy-mm-dd at hh.mm.ss AM|PM
or if the default has been changed it will be to however it's currently set.Setting up the Window-Snapshot.app to be a one* mouse-click solution using CLICLICK
Download CLICLICK and mount the cliclick.dmg file and place a copy of the
cliclick
executable inside the Window-Snapshot.app application bundle at the path show in the script. Ctrl-Click the Window-Snapshot app selecting Show Package Contents and navigate to the Resources folder placing a copy of thecliclick
executable there.Uncomment the two lines below the
(* Note: If using as the one mouse-click solution or Automator Service,
comments by removing the double-dashes,--
, in front of the code.Save the changes made to the AppleScript.
It's now ready to be used as a one* mouse-click solution.
Creating the Window-Snapshot Automator Service
Open Automator selecting Service.
Set Service receives selected to no input leaving in any application as is. Add a Run AppleScript and then copy and paste the Window-Snapshot AppleScript Code above into the Run AppleScript window overwriting the default code.
Uncomment the two lines below the
(* Note: If using as the one mouse-click solution or Automator Service,
comments by removing the double-dashes,--
, in front of the code and set the value of the seconddelay
command to0.25
.Save the Service pressing ⌘S naming it as Window-Snapshot.
Open System Preferences and navigate to Keyboard > Keyboard Shortcuts > Services and scroll to the bottom, then under General you'll see Window-Snapshot and select it. Now click on add shortcut and press shift-command-5 or: ⇧⌘5
It's now ready to be use as a Service using the keyboard shortcut: ⇧⌘5
cliclick
executable to wherever you installed it. You could try putting it in the Services bundle at, e.g./Users/$USER/Library/Services/Window-Snapshot.workflow/Contents
, although I did not try this as I like having it as both an AppleScript application using it as a two mouse-click solution and an Automator Service with keyboard shortcut assigned.In closing, I'd like to say that this very simple AppleScript certainly can be expounded upon to add additional functionality both as an application or a service, i.e. adding code to save the snapshot with different names and locations etc., however I'll leave that to you to modify if you so choose.