1
votes

I'm trying to use AutoHotKey to automate some of my work. When corresponding to customers, I have a template I use. I've created the template and copied it to the clipboard and saved it to a file using an AutoHotKey script - this part worked fine. I now want to save off whatever is in the clipboard, load the pre-saved file, paste it into my Outlook Message window and then restore the saved clipboard back to the clipboard. I've tried this several ways without success - normally, what gets copied to Outlook is whatever is in the clipboard originally. Here are the scripts I've attempted:

^F5::
  ClipSaved := ClipboardAll ; Save the entire clipboard to ClipSaved (Not just text)
  Clipboard =          ; Clear the clipboard
  FileRead, Clipboard, *c <fullpath to saved file like c:\dir\file.clip>
  MyErr = %ErrorLevel%
  if MyErr >= 1
  {
      MsgBox, Unable to read case_format.clip!
  }
  ClipWait, 5
  SendInput, ^v
  Clipboard := ClipSaved        ; Restore the clipboard we saved
  ClipSaved =                   ; Free the memory in case the clipboard was very large
Return

I've also tried using the WinClipApi and it won't work either. It copies nothing and I end up with a 'beep' from windows:

^F5::
    WinClip.Snap( ClipSaved )
    WinClip.Clear()
    WinClip.Load( <full path to file like "c:\dir\file.clip"> )
    ClipWait,5,
    WinClip.Paste()
    WinClip.Restore( ClipSaved )
Return

I've tried mixing and matching pieces (like using the FileRead AHK command in the WinClip example, substituting 'SendInput, ^v' for WinClip.Paste() and so on) but nothing seems to work. Any suggestions?

1
You want Clipboard := ClipSaved, not Clipboard = ClipSavedJim U

1 Answers

0
votes

You might be destroying the clipboard before windows is done processing ctrl+v

This waits for windows to finish pasting before modifying the clipboard

SendInput, ^v
Sleep 2000                   ; Wait 2s for Windows to finish with clipboard
Clipboard := ClipSaved 

The length of the delay depends on what you're pasting. Pasting a 100mb image will require a longer delay than a few lines of text

If your clipboard contains something other than text, consider using clipwait's second parameter:

ClipWait, 2, 1