The next is an instance of what I might do, if I wanted each, to position a display shot on the clipboard and reserve it 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 together 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 beneath: - Save the Automator Service1 as, e.g.: Display Shot to Clipboard and File
- Assign a shortcut, in System Preferences > Keyboard > Shortcuts > Providers:
- Display Shot to Clipboard and File     ⇧⌘5 2
Now while you press ⇧⌘5 2 the crosshair cursor seems simply as if you had pressed ⇧⌘4, nonetheless 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 known as a Fast Motion, so choose that.
- 2 By default, ⇧⌘5 in macOS Mojave is by assigned to a brand new Screenshot function, so attempt ⇧⌘6 as a substitute.
The file naming conference is that of the macOS default for Display Pictures saved usually, in my area. It’s possible you’ll 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 can be, e.g.:
2018-01-13 at 12.04.30 PM
Between the road of code above and the 2 traces that comply with it within the script, they produce, e.g.:
Display 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
, to be able to make changes to format the date and time worth of the theDateTimeNow
variable, as wanted or needed.
Observe: Learn the feedback all through the instance AppleScript code in order to grasp what the script is doing.
This was examined below macOS 10.13.1 and labored for me with out concern.
on run {enter, parameters}
-- # Display 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
-- # Observe that on my system I must keystroke '$' as a substitute of '4'.
-- # I assume it is 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 instances out.
-- # Observe that the day trip additionally acts as an escape key press of kinds. In different
-- # phrases, if the person really presses the escape key it has no impact on this
-- # script like it could if urgent the traditional shortcut exterior of the script.
-- #
-- # As coded, the day trip is 5 seconds. Modify 'or i is bigger than 10' and or
-- # 'delay 0.5' as applicable to your must set a special size day trip.
-- # This implies, as is, you've got 5 seconds to pick the realm of the display you
-- # need to seize and let go of the mouse button, in any other case it instances out.
set i to 0
set isReady to false
repeat till isReady or i is bigger than 10
delay 0.5
set i to i + 1
set cbInfo to (clipboard information) as string
if cbInfo accommodates "class PNGf" then
set isReady to true
finish if
finish repeat
if not isReady then
-- # Consumer 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 habits 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 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
attempt
set fileNumber to open for entry thePathFilename with write permission
write pngData to fileNumber
shut entry fileNumber
on error eStr quantity eNum
attempt
shut entry fileNumber
finish attempt
activate
show dialog eStr & " quantity " & eNum buttons {"OK"} default button 1 with title "File I/O Error..." with icon warning
finish attempt
-- # 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"
attempt
set extension hidden of thePathFilename to true
finish attempt
finish inform
finish run
Observe: The instance AppleScript code above is simply that, and sans the embody error dealing with doesn’t embody another as could also be applicable/wanted/needed, 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.