Skip to content

Instantly share code, notes, and snippets.

@davebrny
Last active July 27, 2023 16:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davebrny/9cb0c53fa049832ab46925f3597637c5 to your computer and use it in GitHub Desktop.
Save davebrny/9cb0c53fa049832ab46925f3597637c5 to your computer and use it in GitHub Desktop.
(autohotkey) - one line clipboard commands
clipboard(string="") {
static clipboard_r
if (string = "/save")
clipboard_r := clipboardAll
else if (string = "/restore")
{
clipboard := clipboard_r
clipboard_r := ""
}
else if (string = "/selected")
{
clipboard := ""
send ^{c}
clipWait, 0.3
return clipboard
}
else if (string = "/paste")
{
send, ^{v}
sleep 100
}
else if (string = "/clear") or (string = "")
clipboard := ""
else
clipboard := string ; set
}
/*
[script info]
version = 1.1
description = one line clipboard commands
author = davebrny
source = https://gist.github.com/davebrny/9cb0c53fa049832ab46925f3597637c5
*/
@davebrny
Copy link
Author

clipboard("/save")     ; save the clipboard state
clipboard("/restore")

clipboard("/selected") ; get selected text
clipboard("/paste")

clipboard("/clear")
clipboard("")

clipboard(string)      ; set the clipboard

@davebrny
Copy link
Author

examples:

clipboard("some text")
msgBox, % clipboard
clipboard("/save")

clipboard("/clear")
msgBox, % clipboard

clipboard("yolo")
msgBox, % clipboard

clipboard("")  ; clear
msgBox, % clipboard

clipboard("more text")

clipboard("/restore")  ; from /save
clipboard("/paste")

send {enter}abc{shift down}{left 3}{shift up}

selected := clipboard("/selected")
msgBox, % selected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment