macos – Copy screenshot to clipboard along with saving the file

macos – Copy screenshot to clipboard along with saving the file


The next is an instance of what I might do, if I wanted each, to put a display shot on the clipboard and put it aside as a file on the identical time.

I might use Automator to create a Service1 workflow, to which a keyboard shortcut could possibly be assigned, to run an AppleScript script to have these two occasions occur along with one another.

In Automator, create a brand new Service1 with the next settings:

  • Service receives (no enter) in (any utility)
  • Add a Run AppleScript motion, changing the default code
    with the instance AppleScript code proven additional under:
  • Save the Automator Service1 as, e.g.: Display screen Shot to Clipboard and File
  • Assign a shortcut, in System Preferences > Keyboard > Shortcuts > Providers:
    • Display screen Shot to Clipboard and File      ⇧⌘5 2

Now whenever you press ⇧⌘5 2 the crosshair cursor seems simply as if you had pressed ⇧⌘4, nevertheless after making the choice as regular and releasing the mouse, the chosen space is each copied to the clipboard and saved to a file on the Desktop.


macOS Mojave Replace:

  • 1 In macOS Mojave, a Service in Automator is now referred to as a Fast Motion, so choose that.
  • 2 By default, ⇧⌘5 in macOS Mojave is by assigned to a brand new Screenshot function, so strive ⇧⌘6 as an alternative.

The file naming conference is that of the macOS default for Display screen Photographs saved usually, in my area. You could want to regulate the next line of code for it to be as in your area:

set theDateTimeNow to (do shell script "date "+%Y-%m-%d at %l.%M.%S %p"")

In my area, this command produces the next instance output the place the worth of the theDateTimeNow variable could be, e.g.:

2018-01-13 at 12.04.30 PM

Between the road of code above and the 2 strains that comply with it within the script, they produce, e.g.:

Display screen Shot 2018-01-13 at 12.04.30 PM.png

In Terminal, take a look on the man web page for each date and strftime, in an effort to make changes to format the date and time worth of the theDateTimeNow variable, as wanted or wished.

Notice: Learn the feedback all through the instance AppleScript code in order to know what the script is doing.

This was examined below macOS 10.13.1 and labored for me with out subject.


on run {enter, parameters}

    --  # Display screen Shot to Clipboard and File

    --  # Clear the clipboard so the 'repeat till isReady ...' loop works correctly.

    set the clipboard to ""

    --  # Copy image of chosen space to the clipboard, press: ⌃⇧⌘4
    --  # Notice that on my system I have to keystroke '$' as an alternative of '4'.
    --  # I assume it's because the 'shift' secret's being pressed.        

    inform utility "System Occasions"
        keystroke "$" utilizing {management down, shift down, command down}
    finish inform

    --  # Wait whereas person makes the choice and releases the mouse or occasions out.
    --  # Notice that the trip additionally acts as an escape key press of types. In different
    --  # phrases, if the person truly presses the escape key it has no impact on this
    --  # script like it will if urgent the traditional shortcut exterior of the script.
    --  #       
    --  # As coded, the trip is 5 seconds. Regulate 'or i is larger than 10' and or  
    --  # 'delay 0.5' as acceptable to your must set a distinct size trip.
    --  # This implies, as is, you may have 5 seconds to pick the realm of the display you
    --  # wish to seize and let go of the mouse button, in any other case it occasions out.

    set i to 0
    set isReady to false
    repeat till isReady or i is larger than 10
        delay 0.5
        set i to i + 1
        set cbInfo to (clipboard data) as string
        if cbInfo incorporates "class PNGf" then
            set isReady to true
        finish if
    finish repeat
    if not isReady then
        --  # Person both pressed the Esc key or timed out ready.
        return  --  # Exit the script with out additional processing.
    finish if

    --  # Construct out the display shot path filename so its conference is of 
    --  # the default conduct when saving a display shot to the Desktop.

    set theDateTimeNow to (do shell script "date "+%Y-%m-%d at %l.%M.%S %p"")
    set theFilename to "Display screen Shot " & theDateTimeNow & ".png"
    set thePathFilename to POSIX path of (path to desktop folder as string) & theFilename

    --  # Retrieve the PNG knowledge from the clipboard and write it to a disk file.

    set pngData to the clipboard as «class PNGf»
    delay 0.5
    strive
        set fileNumber to open for entry thePathFilename with write permission
        write pngData to fileNumber
        shut entry fileNumber
    on error eStr quantity eNum
        strive
            shut entry fileNumber
        finish strive
        activate
        show dialog eStr & " quantity " & eNum buttons {"OK"} default button 1 with title "File I/O Error..." with icon warning
    finish strive

    --  # Convert the POSIX path filename to an alias.

    set thePathFilename to POSIX file thePathFilename as alias

    --  # Cover the file extension as is the default.

    inform utility "Finder"
        strive
            set extension hidden of thePathFilename to true
        finish strive
    finish inform

finish run

Notice: The instance AppleScript code above is simply that, and sans the embody error dealing with doesn’t embody some other as could also be acceptable/wanted/wished, the onus is upon the person so as to add any error dealing with for any instance code offered and or code written by the oneself.

Leave a Reply

Your email address will not be published. Required fields are marked *