TIP - Retaining the Clipboard contents

I've seen, that most of the scripts shared in this forum, if they use the clipboard, they will erase what you have copied before you start the script, but you would probably often need the (original) clipbord content, when the script has finished. – Therefore you could do the following:

[your hotkey to start the script]::
    temp := ClipboardAll
    ...
    [your script including ^c or other clipboard use]
    ...
    clipboard := temp
    temp =
    return

Notes:

  1. temp retains the clipboard content for you until the script does no longer use the clipboard
  2. with the last step, the temp variable is cleared
Parents
  • Thank you Host-Helge! This is a good reminder.

    I confess that I have several scripts where the clipboard contents are not preserved at all. And I'm probably wrong, but sometimes it feels like using the clipboard preservation lines seems to affect the deployment of the script.

    For example, this short script that came up in the forum yesterday:

    ;Freetranslation.com lookup
    !f::
    OldClipboard:= Clipboard
    Clipboard:= ""
    Send, ^c ;copies selected text
    ClipWait
    Run www.freetranslation.com/search
    Sleep 2000
    Send ^v
    Clipboard:= OldClipboard
    Return

    I couldn't get that to work until I changed it to:

    ;Freetranslation.com lookup
    !f::
    Sleep 200
    Send, ^c
    ClipWait
    Run www.freetranslation.com/search
    Sleep 2000
    Send ^v
    Send, +{Tab} ;added later to move the focus to the Translate button
    Send, {Enter} ;to "click" the Translate button
    Return

    With the first script, the selected text was not being sent to the clipboard, and the old contents of the clipboard were being pasted into the search box.
Reply
  • Thank you Host-Helge! This is a good reminder.

    I confess that I have several scripts where the clipboard contents are not preserved at all. And I'm probably wrong, but sometimes it feels like using the clipboard preservation lines seems to affect the deployment of the script.

    For example, this short script that came up in the forum yesterday:

    ;Freetranslation.com lookup
    !f::
    OldClipboard:= Clipboard
    Clipboard:= ""
    Send, ^c ;copies selected text
    ClipWait
    Run www.freetranslation.com/search
    Sleep 2000
    Send ^v
    Clipboard:= OldClipboard
    Return

    I couldn't get that to work until I changed it to:

    ;Freetranslation.com lookup
    !f::
    Sleep 200
    Send, ^c
    ClipWait
    Run www.freetranslation.com/search
    Sleep 2000
    Send ^v
    Send, +{Tab} ;added later to move the focus to the Translate button
    Send, {Enter} ;to "click" the Translate button
    Return

    With the first script, the selected text was not being sent to the clipboard, and the old contents of the clipboard were being pasted into the search box.
Children
No Data