Page 1 of 1

Copy and Paste

Posted: 20 May 2018, 09:14
by Reast
Hi, i need simple script that copy selected text with F6 to file on desktop mix.txt, and next time F6 add selected text at the end of that file. I try to do myself but i am new to this.

Re: Copy and Paste  Topic is solved

Posted: 20 May 2018, 13:58
by wolf_II
Try this simple code:

Code: Select all



; hotkey to collect selected texts in a file
;-------------------------------------------------------------------------------
F6:: FileAppend, % get_Highlight(), %A_Desktop%\mix.txt
;-------------------------------------------------------------------------------



;-------------------------------------------------------------------------------
get_Highlight() { ; get highlighted text
;-------------------------------------------------------------------------------
    ClipStore := ClipboardAll           ; remember current content
    Send, ^c                            ; copy highlighted text
    ClipWait, 1                         ; wait for change
    Result := Clipboard                 ; store highlighted text
    Clipboard := ClipStore              ; restore previous content
    Return, Result
}
I hope that helps.

More sophisticated is with a delimiter:

Code: Select all

#NoEnv
#SingleInstance, Force
Delimiter := "`n`n"
Return ; end of auto-execute section



; hotkey to collect selected texts in a file
;-------------------------------------------------------------------------------
F6:: FileAppend, % get_Highlight() Delimiter, %A_Desktop%\mix.txt
;-------------------------------------------------------------------------------



;-------------------------------------------------------------------------------
get_Highlight() { ; get highlighted text
;-------------------------------------------------------------------------------
    ClipStore := ClipboardAll           ; remember current content
    Send, ^c                            ; copy highlighted text
    ClipWait, 1                         ; wait for change
    Result := Clipboard                 ; store highlighted text
    Clipboard := ClipStore              ; restore previous content
    Return, Result
}

Re: Copy and Paste

Posted: 20 May 2018, 14:30
by Reast
Work great, thank you very much:)