clipboard to file saved content de-rates after PC restart

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
henryw
Posts: 4
Joined: 20 Jun 2022, 00:36

clipboard to file saved content de-rates after PC restart

Post by henryw » 22 Jun 2022, 00:10

Hello !
my issue is a bit difficult to describe but I will try without screen recording...

Code: Select all

/* --------------------------------------------------------------------------------------
    - .de language version
    - clip board needs to contain the correct snippet
    - save current clip board as channel header to file.
    - this creates pre-saved clipboard file (overwrites !)
    - has to run once to setup clip files
   --------------------------------------------------------------------------------------
*/
::tsSaveHeader.de::
FileToHandle := WorkingPath . "TeamsChannelHeader_DE.clip"

if (FileExist( FileToHandle )) {
    FileDelete, %FileToHandle%                                          ;always empty file needed
}
ClipBackup := ClipboardAll
FileAppend, %ClipBackup%, %FileToHandle%
return

/* --------------------------------------------------------------------------------------
    - inserts .de project header template .de version
    - pre-saved Clipboard file needed !
   --------------------------------------------------------------------------------------
*/
^H::
::tsChHeader.de::
InsertClipBoard(WorkingPath . "TeamsChannelHeader_DE.clip")
return



/* --------------------------------------------------------------------------------------
    Function:   InsertClipBoard( File )
    File:       path and clipboard file name. Clipboard file has to be created before
    Feedback:   error message if specified clipboard file does not exist
   --------------------------------------------------------------------------------------
*/
InsertClipBoard( FilePathAndName ) {
    if (FileExist( FilePathAndName )) {
        FileRead, TempClip, *c %FilePathAndName%
        File.Close()
        Clipboard:= TempClip
        Sleep 500
        send ^v
    }

    else {
        MsgBox, %FilePathAndName% "file not found"
    }
}
The feature I need to implement is to insert formatted text into MS TEAMS threads & answers.
MS Teams documentation does not publish any text format information. So the clipboard seems to be THE SOLUTION.
Well yes temporary.

If I save a clipboard content (formatted text; grep from TEAMS as template) to a file via AHK hot-string 'tsSaveHeader.de' this works fine.
2022-06-22 Microsoft Teams.jpg
2022-06-22 Microsoft Teams.jpg (29.71 KiB) Viewed 732 times
The re-use of the clipboard content via hot-string 'tsChHeader.de' works fine also.
When PC is shutdown and restarted, the insertion results in plain text only. No formatted text is inserted unless one updates the *.clip file
This effect is not related to MS TEAMS but any other application like WORD also. To me this is an indication AHK may not cause the issue but "participates"
Any idea ?

Thanks


RussF
Posts: 1264
Joined: 05 Aug 2021, 06:36

Re: clipboard to file saved content de-rates after PC restart

Post by RussF » 22 Jun 2022, 14:28

Just spitballing here - have you tried saving and loading directly from the clipboard rather than an intermediate variable as shown in the ClipboardAll documentation:
ClipboardAll may also be saved to a file (in this mode, FileAppend always overwrites any existing file):

FileAppend, %ClipboardAll%, C:\Company Logo.clip ; The file extension does not matter.
To later load the file back onto the clipboard (or into a variable), follow this example:

FileRead, Clipboard, *c C:\Company Logo.clip ; Note the use of *c, which must precede the filename.
The docs have quite a number of limitations on saving and loading the binary data. Perhaps a deeper dive and further experimentation is needed?

Russ

ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: clipboard to file saved content de-rates after PC restart

Post by ahk7 » 22 Jun 2022, 14:50

Things to try:
* Save/create your template as html, search the forum for SetClipboardHTML() to paste it
* Save/create your template as Word document, search the forum for com word something like ActiveDocument.range.text to read and then paste)
* Search the forum for winclip to save/read various formats incl. html

henryw
Posts: 4
Joined: 20 Jun 2022, 00:36

Re: clipboard to file saved content de-rates after PC restart

Post by henryw » 28 Jun 2022, 05:19

Hallo Russ,
well I do not agree.
In case of WRITING: ClipboardAll is copied to ClipBackup and then written to file ( I would call this intermediate...)
In case of READING: file content is written to TempClip and then to Clipboard. (ClipboardAll can not be used as destination for copying data to.

henryw
Posts: 4
Joined: 20 Jun 2022, 00:36

Re: clipboard to file saved content de-rates after PC restart

Post by henryw » 28 Jun 2022, 05:20

ahk7 wrote:
22 Jun 2022, 14:50
Things to try:
* Save/create your template as html, search the forum for SetClipboardHTML() to paste it
* Save/create your template as Word document, search the forum for com word something like ActiveDocument.range.text to read and then paste)
* Search the forum for winclip to save/read various formats incl. html
Thanks for this attempt to solve. I will try as soon as possible

RussF
Posts: 1264
Joined: 05 Aug 2021, 06:36

Re: clipboard to file saved content de-rates after PC restart

Post by RussF » 28 Jun 2022, 05:57

henryw wrote:
28 Jun 2022, 05:19
Hallo Russ,
well I do not agree.
In case of WRITING: ClipboardAll is copied to ClipBackup and then written to file ( I would call this intermediate...)
In case of READING: file content is written to TempClip and then to Clipboard. (ClipboardAll can not be used as destination for copying data to.
RussF wrote: have you tried saving and loading directly from the clipboard rather than an intermediate variable as shown in the ClipboardAll documentation:
Apparently, you misunderstood my suggestion. The documentation for ClipboardAll gives this example for writing to a file:
FileAppend, %ClipboardAll%, C:\Company Logo.clip ; The file extension does not matter.
There is no intermediate variable.

Russ

henryw
Posts: 4
Joined: 20 Jun 2022, 00:36

Re: clipboard to file saved content de-rates after PC restart

Post by henryw » 30 Jun 2022, 02:09

Ok I misunderstood, but there is no difference in result - with out out the variable

Post Reply

Return to “Ask for Help (v1)”