Author Topic: Save to file from windows Clipboard  (Read 2065 times)

Peter Dulong

  • Newbie
  • *
  • Posts: 31
Save to file from windows Clipboard
« on: August 07, 2023, 12:21:00 PM »
How do I save to a file from the Windows clip board? Is there a token or special Command i could use to achieve this?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Save to file from windows Clipboard
« Reply #1 on: August 07, 2023, 06:24:19 PM »
If you're referring specifically to saving text from the clipboard to a file, the "{CLIP}" token can be used, however if the text you are copying contains pairs or curly braces ("{" followed by "}"), those would be removed by the token parser.

To work around that, the contents of the clipboard need to be escaped, which must be done using an inline function, as the "Replace with" option of the "Set a Text Value" action is applied after the token parser (by necessity; otherwise you wouldn't be able to get values from tokens).

This C# inline function should serve that purpose for normal text input:
Code: [Select]
using System.Windows.Forms;

public class VAInline
{
public void main()
{
VA.SetText("~clipboardText", Clipboard.GetText().Replace("{", "||{").Replace("}", "||}"));
}
}

which could then be followed by the "Write Text to a File" action:
Code: [Select]
Write (do not overwrite), '{TXT:~clipboardText}' to file 'C:\Users\Sysadmin\Desktop\clipboardText.txt'
Do note that the "{TXT:}" token, specifically, seemingly cannot be escaped correctly in VoiceAttack v1.10.6.14 or earlier (E.G. "{TXT:my text}" in the clipboard would result in "|Not set" written to the file, whereas something like"{BOOL:my bool}" would correctly result in "{BOOL:my bool}")

Peter Dulong

  • Newbie
  • *
  • Posts: 31
Re: Save to file from windows Clipboard
« Reply #2 on: August 08, 2023, 08:41:13 AM »
Thank you so much for that, it works perfectly, You are amazing when it comes to helping out. I only hope someday I can return the favour. 8)