0

I'm trying to implement a feature by which the user can directly copy a piece of text into a specific file. (mini-clipboard type)

The first thing I researched about was of creating a universal context menu by which the user can select(/mark) the text he wants to copy to that file and then select a specific universal option (eg. Save to ..). But I then later realized that all applications have their own context menu so it is practically impossible to anything of that sort.

The next thing that came into my mind was of using custom shortcut to copy some text into a specific file,

https://www.laptopmag.com/articles/create-keyboard-shortcuts-windows-10

Is there any way to get the current selected text, create a shortcut to that specific batch file and pass then selected text as a parameter to that batch-file?

We could use a text file as a temp storage for the current contents of the clipboard but the main question is how would I copy the content by just using one shortcut?

  • There are a number of third-party clipboard replacements that store copied text in a file. – DrMoishe Pippik Jan 31 at 21:00
  • I don't want to really replicate them, but I am I'm trying to achieve something else altogether. Could you name a few maybe I'll get some idea of as to how can I solve this problem by by myself? – Hello World Feb 1 at 3:31
  • Say you had to add another shortcut similar to Ctrl+C which would not only copy the currently marked contents but also execute a set of commands. How would you achieve it? – Hello World Feb 1 at 3:35
  • You intents is get a text in one file and add to another one, where the path to saved file will chose by dialogue box, or in a existent file with the context menu is used to open and past to selected one? Sorry my english, I’ve have one option to suggest. – It Wasn't Me Feb 13 at 0:17
  • @ItWasn'tMe The user will mark some text, press a key (SAY Ctrl+F9) and a window shall appear to him. So in my case, the user will select/mark text from literally any window and press the shortcut key. The selected text should become the contents of a file, so that the file name can be passed as the parameters to another file. Please post whatever is in your mind, maybe it could turn out to be the right answer.. – Hello World Feb 14 at 20:29
0

Using AutoHotkey:

; Copy some text and use a text file as a temp storage for the current contents of the clipboard:

F1::
ClipSaved := ClipboardAll       ; save the entire clipboard to the variable ClipSaved
Clipboard := ""                 ; empty the clipboard (start off empty to allow ClipWait to detect when the text has arrived)
Send, ^c                        ; copy the selected text
ClipWait, 1                     ; wait for the clipboard to contain data. 
if (!ErrorLevel)                ; if NOT ErrorLevel ClipWait found data on the clipboard
{
    FileDelete, TempClipboardText.txt 
    FileAppend, %clipboard%`n, TempClipboardText.txt
}
Sleep, 300                      ; Don't change clipboard while appending or pasting! (Sleep > 0)
clipboard := ClipSaved          ; restore original clipboard
VarSetCapacity(ClipSaved, 0)    ; Free the memory
return

; Copy the content of TempClipboardText.txt at a later point in time  using FileRead with the *c option:

F2::
ClipSaved := ClipboardAll        ; save the entire clipboard to the variable ClipSaved
Clipboard := ""                  ; empty the clipboard (start off empty to allow ClipWait to detect when the text has arrived)
FileRead, Clipboard, *c TempClipboardText.txt   ; Copy the content of TempClipboardText.txt
ClipWait, 2
if (ErrorLevel)                  ; if ErrorLevel ClipWait found no data on the clipboard
{
    MsgBox, Can not read "TempClipboardText.txt"
    clipboard := ClipSaved       ; restore original clipboard
    VarSetCapacity(ClipSaved, 0) ; Free the memory
}
return

https://www.autohotkey.com/docs/misc/Clipboard.htm https://www.autohotkey.com/docs/commands/FileAppend.htm https://www.autohotkey.com/docs/commands/FileRead.htm

  • Is there any way to copy the last selected text with or without AutoHotKey? – Hello World Feb 1 at 9:03
  • The shortcut Control+C copies the last selected text in the active window. What set of commands do you want to use after Control+C? – user3419297 Feb 1 at 9:40
  • I want to do it in one go. So if the user selects some text and strokes a specific shortcut, the text should automatically get saved to that file. – Hello World Feb 1 at 9:46
  • The first hotkey in the above example does exactly this. – user3419297 Feb 1 at 10:09
  • Is there any way to avoid AutoHotKey? – Hello World Feb 1 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.