Save screenshot with document name and page
Is it possible to add the document name and document page when I do screenshots?

Using just what's setup by default, no; however, aside from doing it manually, it can be automated to various degrees depending on what methods and applications are involved.

So, if I open a PDF and do a screenshot at page 6, I will have: Document Name | Page 6 | Screen Shot 2012-06-12 at 8.02.40 AM

As an example, using Preview and AppleScript along with an Automator Service/Quick Action, and assigning it a keyboard shortcut in System Preferences &gt; Keyboard &gt; Shortcuts &gt; Services, the example AppleScript code, shown further below, will take a screen shot of either the full window of the front window of Preview or just its document scroll area, depending on its settings.
The name of the screen shot will be in the format shown quoted above from your question.

Here is a sample file name and a scaled down image of the screen shot taken of the document scroll area in Preview of The Room Where It Happened and was saved as:
    The Room Where It Happened | 3 | Snap Shot 2020-7-7 at 8.55.30 PM.png


There are three variables at the start of the example AppleScript code that are user configurable:

saveToLocation - Where the screen shot will be saved.

The default is the users Pictures folder.


ssFileType - Which can be set to: png, jpg, pdf or tiff.

The default is: png


captureArea - Which gets set to to either whole window, or scroll area.

The default is: scroll area (of the document, not whatever shows in the Sidebar.)



You should not need to edit the code below these initial variables, unless necessary, and the code is lightly commented to help one understand what it is doing.

The following example AppleScript code was tested as an Automator Service in macOS High Sierra, and should also work as a Quick Action in macOS Mojave and later. The Automator Service was assigned a keyboard shortcut of ⌥⌘S and was pressed while Preview had focus and was frontmost.
--  # Set the save to location, screen shot file type, and the capture area.
--  # The code below these three settings should not need to be edited.

--  # The saveToLocation must be in the form of a 
--  # POSIX path for the screencapture command.

set saveToLocation to POSIX path of (path to pictures folder)

--  # ssFileType can be set to &quot;png&quot;, &quot;jpg&quot;, &quot;pdf&quot; or &quot;tiff&quot;.

set ssFileType to &quot;png&quot;

--  # Set the capture area to either 'whole window', or just the 'scroll area'.

set captureArea to &quot;scroll area&quot;


--  # Do not edit the code below this line unless necessary.


--  # In Preview, when a PDF document is opened, the 'window name' is in the
--  # format of 'filename (page x of y)' for multi-page documents, or  
--  # 'filename (1 page)' for single-page documents, and the 'filename' may contain '.pdf'.
--  # Example: &quot;The Room Where It Happened.pdf (page 1 of 570)&quot;
--  # Parse the text items of the 'window name' for parts of the screen shot name.


--  # Get then name of the first window of Preview.

tell application &quot;System Events&quot; to ¬
    set windowName to ¬
        the name of ¬
            the front window of ¬
                application process &quot;Preview&quot;

--  # Check to see the document is a PDF, and terminate if not.

if windowName contains &quot;(page&quot; or windowName contains &quot;page)&quot; then
    -- # Document is a PDF file. Continue processing...
else
    return
end if

--  # Parse 'windowName' to get the doc name and page number.

set text item delimiters to &quot;(&quot;

set documentName to ¬
    the first text item of ¬
        the windowName

if documentName contains &quot;.pdf&quot; then
    set documentName to ¬
        characters 1 thru -6 of ¬
        the first text item of ¬
            the windowName
else
    set documentName to ¬
        characters 1 thru -2 of ¬
        the first text item of ¬
            the windowName
end if

if the first word of ¬
    the second text item of ¬
        the windowName is &quot;1&quot; then
    set pageNumber to ¬
        the first word of ¬
            the second text item of ¬
                the windowName
else
    set pageNumber to ¬
        the second word of ¬
            the second text item of ¬
                the windowName
end if

set text item delimiters to &quot;&quot;

--  # Get position and size of the front window or the
--  # document scroll area of Preview for the screen shot.

if captureArea contains &quot;whole window&quot; then
    tell application &quot;System Events&quot; to ¬
        set windowPositionSize to {position, size} of ¬
            the front window of ¬
                application process &quot;Preview&quot;
else if captureArea contains &quot;scroll area&quot; then
    tell application &quot;System Events&quot;
        if exists scroll area 2 of ¬
            splitter group 1 of ¬
            window 1 of ¬
            application process &quot;Preview&quot; then
            set windowPositionSize to ¬
                {position, size} of ¬
                scroll area 2 of ¬
                splitter group 1 of ¬
                window 1 of ¬
                application process &quot;Preview&quot;
        else
            set windowPositionSize to ¬
                {position, size} of ¬
                scroll area 1 of ¬
                splitter group 1 of ¬
                window 1 of ¬
                application process &quot;Preview&quot;
        end if
    end tell
end if

set x to item 1 of item 1 of windowPositionSize
set y to item 2 of item 1 of windowPositionSize
set w to item 1 of item 2 of windowPositionSize
set h to item 2 of item 2 of windowPositionSize

--  # Build out the date time string for the screen shot file name.

set currentDate to (current date)
set d to day of currentDate
set m to month of currentDate as integer
set yr to year of currentDate
set t to time string of currentDate

--  # Replace ':' with '.' in the 'time string'.

set text item delimiters to &quot;:&quot;
set t to text items of t
set text item delimiters to &quot;.&quot;
set t to t as string
set text item delimiters to &quot;&quot;

--  # Set the screen shot file name.

set ssFileName to ¬
    (documentName as string) &amp; ¬
    &quot; | &quot; &amp; ¬
    pageNumber &amp; ¬
    &quot; | &quot; &amp; ¬
    &quot;Snap Shot &quot; &amp; yr &amp; &quot;-&quot; &amp; d &amp; &quot;-&quot; &amp; m &amp; &quot; at &quot; &amp; t &amp; &quot;.&quot; &amp; ssFileType

--  # Define the shell command.

set myShellCMD to ¬
    &quot;screencapture -R&quot; &amp; x &amp; &quot;,&quot; &amp; y &amp; &quot;,&quot; &amp; w &amp; &quot;,&quot; &amp; h &amp; &quot; -t &quot; &amp; ¬
    ssFileType &amp; space &amp; (saveToLocation &amp; ssFileName)'s quoted form

--  # Take the screen shot.

do shell script myShellCMD


For the Run Shell Script action in the Automator Service/Quick Action, replace the entire default code with the example AppleScript code, and then edit the first three variables as wanted, if the default values are not what you want.

Note: The example AppleScript code is just that and does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.