-11.6 C
United States of America
Monday, January 20, 2025

How do I modify the folder screenshots are saved to on this AppleScript in Automator?


This apple script appears to be doing precisely what I wished it to do, (save screenshots each to a file location and to the clipboard) however I can not for the lifetime of me determine how one can change this script to level at a special folder (at present it’s saving to the Desktop)

I am not very conversant in Automator or AppleScript and have not been capable of pin down the place that’s being set in order that I can change it
This line appears to be like related:

set thePathFilename to POSIX path of (path to desktop folder as string) & theFilename

And that is the complete script

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
--  # Observe that on my system I have to keystroke '$' as an alternative of '4'.
--  # I assume it's because the 'shift' key'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.
--  # Observe that the day out 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 will if urgent the conventional shortcut exterior of the script.
--  #       
--  # As coded, the day out is 5 seconds. Alter 'or i is larger than 10' and or  
--  # 'delay 0.5' as acceptable in your must set a special size day out.
--  # This implies, as is, you may have 5 seconds to pick the realm of the display screen 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 screen shot path filename so its conference is of 
--  # the default conduct when saving a display screen 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 information 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

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

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

Which I discovered right here: Copy screenshot to clipboard along with saving the file

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles