3
votes

Using Autohotkey, Id like to concatenate the variable1, the clipboard contents, and variable2.

For example, if:

  1. variable1 = https://example.com/somepage.php?command=details&reservationId=
  2. clipboard contents = 12345
  3. variable2 = &url=%2Fsomepage.php%3submit%3DSEARCH%26submit

The expected result would be:

https://example.com/somepage.php?command=details&reservationId=12345&url=%2Fsomepage.php%3submit%3DSEARCH%26submit


The two methods shown below simply output 12345

What am I doing wrong?

Attempt 1:

::hd-eurl::
 ClipSaved := ClipboardAll       ; get clipboard
 variable1:= "https://example.com/somepage.php?command=details&reservationId="
 variable2:= "&url=%2Fsomepage.php%3submit%3DSEARCH%26submit"
 ClipNew =  %variable1% . ClipSaved . %variable2%
 clipboard = ClipNew 
 ClipWait
 Send, ^v
 clipboard := ClipSaved       ; restore original clipboard
 return

Attempt 2:

::hd-eurl::
 Send ^c
 ClipSaved := ClipboardAll       ; get clipboard
 variable1= https://example.com/somepage.php?command=details&reservationId=
 variable2= &url=`%2Fsomepage.php`%3submit`%3DSEARCH`%26submit
 ClipNew =  variable1 . ClipSaved . variable2
 clipboard = ClipNew 
 ClipWait
 Send, ^v
 clipboard := ClipSaved       ; restore original clipboard
 return

Update (same results):

::hd-eurl::
 ClipSaved := ClipboardAll       ; get clipboard
 variable1:= "https://example.com/somepage.php?command=details&reservationId="
 variable2:= "&url=%2Fsomepage.php%3submit%3DSEARCH%26submit"
 ClipNew :=  variable1 . ClipSaved . variable2
 clipboard := ClipNew 
 ClipWait
 Send, ^v
 clipboard := ClipSaved       ; restore original clipboard
 return

Working Solution

This is how I finally got it working. However, Blauhirn's method in the selected answer is much simpler to use.

::hd-eurl::
 ClipSaved := ClipboardAll       ; store clipboard backup 
 variable1:= "https://example.com/somepage.php?command=details&reservationId="
 variable2=  %ClipBoard%
 ClipBoard =
 variable3:= "&url=%2Fsomepage.php%3submit%3DSEARCH%26submit"
 variable4:=  variable1 . variable2 . variable3
 Clipboard:= variable4
 ClipWait 
 Send, ^v
 Clipboard := ClipSaved       ; restore original clipboard
 return
2

2 Answers

2
votes

Your clipSaved variable contains clipboardAll. Documentation says:

Variables to which ClipboardAll has been assigned are in binary format and thus will appear as gibberish when displayed with MsgBox or similar.

You have to use clipboard instead when assigning to clipNew, like

 ClipNew := variable1 . clipboard . variable2

Apart from that, I suggest you do not modify the contents of clipboard at all, for this is the most complicated way to do it. If you want to send something, just use the send command on the very string instead of calling CTRL+V:

::hd-eurl::
    variable1:= "https://example.com/somepage.php?command=details&reservationId="
    variable2:= "&url=%2Fsomepage.php%3submit%3DSEARCH%26submit"
    send % variable1 clipboard variable2
return
1
votes

correct syntax is

ClipNew :=  variable1 . ClipSaved . variable2

or

ClipNew =  %variable1%%ClipSaved%%variable2%

Variables and expressions

also modify this line

clipboard := ClipNew