How to run in background script that set Word as clipboard?

Discussion, questions and support.
Posts: 53
Joined: Sat Jun 06, 2015 2:28 am

How to run in background script that set Word as clipboard?

PostPosted by cadudesun » Sun Apr 23, 2017 7:37 pm

Hi,

I'd appreciate help. I recorded my screen detailing the issue - https://goo.gl/AsOtHs - which is:

I need to copy/paste text from app A to app B.
The problem is text from app A is copied as RTF and app B just accepts HTML (and vice-versa), and I need text colors and highlights being transferred between them.
I realized MS Word can be used as a kind of clipboard/transfer area, since when I paste text from those Apps into Word first, and then copy from Word, the text is copied as RTF+HTML and can be pasted into the Apps with all text colors and highlights.

I'm already using the following command that performs the core functionality described above, except that the operation runs in the foreground. I mean, I see Word being opened, text pasted, copied, Word minimized, etc.

Code: Select all
Run, winword
WinWaitActive, ahk_class OpusApp
WinGet, WordId, ID
WinMinimize, ahk_id %WordID%
Return
^#c::
   ClipBoard =
   Send ^c
   ClipWait, 1
   SendMode, Input
   WinRestore, ahk_id %WordID%
   WinWaitActive, ahk_id %WordID%
   Send ^v
   sleep 1200
   ClipBoard =
   Send ^a
   sleep 500
   Send ^x
   ClipWait, 1
   WinMinimize, ahk_id %WordID%
Return


I'd rather everything running in the background. I would press #^c and I just need to be confident what is in my clipboard is ready to paste.

Is it possible to run the script having Word operating in the background? How to improve the mentioned command?

Many thanks for assistance,
Carlos

Posts: 53
Joined: Sat Jun 06, 2015 2:28 am

Re: How to run in background script that set Word as clipboa

PostPosted by cadudesun » Mon Apr 24, 2017 6:16 pm

Hi,

The script below, shared by kon, is working as expected (Word operating in the background).
However, it just works when I run the script through AHK.
If I run very same syntax as a Fastkeys command, there is the error "0x80001010D - An outgoing call cannot be made..." (error snapshot: http://i.imgur.com/c54HMlF.png).
I recorded my screen showing the issue too: https://goo.gl/1i4Cf9
How to make the script runs properly from Fastkeys too?

Code: Select all
; Constants
wdMainTextStory := 1

wdApp := ComObjCreate("Word.Application")   ; Create an instance of Word.
wdApp.Visible := true                       ; Make Word visible.
NotesDoc := wdApp.Documents.Add()           ; Add a new document to Word.
return                                      ; End of auto-execute section.

^#c::                   ; Ctrl+Win+C hotkey
    Clipboard := ""     ; Clear the clipboard
    Send, ^c            ; Copy
    ClipWait, 1         ; Wait for the clipboard to contain any data.
    if (ErrorLevel)     ; If error...
        return
    NotesDoc.StoryRanges(wdMainTextStory).Paste  ; Paste the contents of the clipboard into Word.
    NotesDoc.StoryRanges(wdMainTextStory).Copy   ; Copy the main text story Range.
    TrayTip, Copied, Successfully copied from Word.
return

Site Admin
User avatar
Posts: 628
Joined: Sat Mar 02, 2013 9:02 pm

Re: How to run in background script that set Word as clipboa

PostPosted by Marko » Tue Apr 25, 2017 8:42 pm

Try running it by using Script mode. Copy the script to text file, like MyScript.ahk and then set the item with Type: Script.

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests