Copy two items and paste them sequentially Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Copy two items and paste them sequentially

03 Aug 2021, 23:04

This code gives the number of times a script has run in a month.

Code: Select all

;ONLY COUNT
ini := StrReplace(A_ScriptFullPath, ".ahk", ".ini"), track := "Track"
IniRead, year , %ini%, %track%, year
IniRead, month, %ini%, %track%, month
IniRead, runs , %ini%, %track%, runs, 0
If (year != A_YYYY || month != A_MM) {
       IniWrite, %A_YYYY%   , %ini%, %track%, year
       IniWrite, %A_MM%     , %ini%, %track%, month
       IniWrite, % runs := 1, %ini%, %track%, runs
} Else IniWrite, % ++runs   , %ini%, %track%, runs

;WITH MONTH
lastMonth := lastMonth("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Spt", "Oct", "Nov", "Dec")

;MsgBox  %lastMonth%
lastMonth(list*)	;this way you can decide how the element should count back.i.e a string like Feb, or 02...
{
Index := A_Mon -0
lastMon .= list[Index]
Return, %lastMon%
; Return, list[Index]	;to only return the month
}

;DISPLAY IN MSGBOX
MsgBox , 0,   Runs - %runs%

I want ahk to

1.First enter the current date ( in the format - 04-Aug-2021)

2.copy any other text of my choice ( this I will do manually )

3.and on sending ctrl v ,
the date should get entered,
msgbox contents should get pasted first,
a gap of two lines should be given
and then the text that I would have copied should get pasted

eg.
04-Aug-2021
Runs 10 ( Runs - %runs%)
"gap"
"gap"
(the text I copied manually)


can someone please help/guide me ?

ps. I will paste all of the above into a chat service (sms e.t.c)
User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Copy two items and paste them sequentially

03 Aug 2021, 23:13

Code: Select all

ini := StrReplace(A_ScriptFullPath, ".ahk", ".ini"), track := "Track"
IniRead, year , %ini%, %track%, year
IniRead, month, %ini%, %track%, month
IniRead, runs , %ini%, %track%, runs, 0
If (year != A_YYYY || month != A_MMM) {
       IniWrite, %A_YYYY%   , %ini%, %track%, year
       IniWrite, %A_MMM%    , %ini%, %track%, month
       IniWrite, % runs := 1, %ini%, %track%, runs
} Else IniWrite, % ++runs   , %ini%, %track%, runs
MsgBox, 0, %A_MMM% %A_YYYY% runs, %runs%
^v::SendInput % "{Text}" A_MMM " Runs " runs "`n`n`n" Clipboard
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Copy two items and paste them sequentially

03 Aug 2021, 23:21

@mikeyww

it is now pasting the entire code along with msgbox's contents

I forgot to mention that once the msgbox's contents and the text of my choice get pasted , the clipboard should get cleared
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Copy two items and paste them sequentially

04 Aug 2021, 00:38

To explain it more clearly,
this code is at the beginning of the script

Code: Select all


;ONLY COUNT

ini := StrReplace(A_ScriptFullPath, ".ahk", ".ini"), track := "Track"
IniRead, year , %ini%, %track%, year
IniRead, month, %ini%, %track%, month
IniRead, runs , %ini%, %track%, runs, 0
If (year != A_YYYY || month != A_MM) {
       IniWrite, %A_YYYY%   , %ini%, %track%, year
       IniWrite, %A_MM%     , %ini%, %track%, month
       IniWrite, % runs := 1, %ini%, %track%, runs
} Else IniWrite, % ++runs   , %ini%, %track%, runs



;WITH MONTH

lastMonth := lastMonth("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Spt", "Oct", "Nov", "Dec")

;MsgBox  %lastMonth%
lastMonth(list*)	;this way you can decide how the element should count back.i.e a string like Feb, or 02...
{
Index := A_Mon -0
lastMon .= list[Index]
Return, %lastMon%
; Return, list[Index]	;to only return the month
}

After some more codes is the part where it sends ctrl v

at the very end of the script is this code

Code: Select all

MsgBox , 0,  - %lastMonth%,     Runs - %runs%, 5
after the script runs the msgbox displays the month and the number of times the script has run


But I want the

Current date ( DD-MMM-YYYY)
"gap"
Runs - %runs%
"gap"
"gap"
the text I copy, ( which is a zoom link that gets copied automatically once the meeting starts ) ready to be pasted into the chat service

As I understand the 'number of runs' e.t.c data cannot be pulled from the msgbox as it's at the end of the script and the part where the pasting is done is somewhere in the middle



( ahk with a series of macros opens the person's chat and pasts the link

Now along with that link I want the aforementioned data to be pasted as well)


Once the data is pasted and sent, the clipboard should be cleared
User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Copy two items and paste them sequentially

04 Aug 2021, 09:21

You can use any variables that you have to populate the clipboard. Clipboard is a special AHK variable that is the contents of the Windows clipboard. You can set it and retrieve it like other variables, so set it to the string that you have described here.

Code: Select all

Clipboard = abc
runs = 99
Sleep, 100
Clipboard = %A_DD%-%A_MMM%-%A_YYYY%`n`nRuns - %runs%`n`n`n%Clipboard%
Sleep, 100
Send ^v
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Copy two items and paste them sequentially

04 Aug 2021, 10:40

@mikeyww

Its sort of working fine

the date and the runs are getting pasted
but the part where the zoom link is supposed to be pasted, "abc" is taking it's place


the sequence of the macro is

1.the zoom application gets opened and a meeting is started,
( I have set the link to get copied once the meeting starts )

2. the chat application is opened , the copied zoom link gets pasted

I feel the first entry into the windows clipboard is the copied zoom link

then the month and number of runs ( the code which copies the date and the number of runs is after the code where zoom link gets copied )


But when it is set to be pasted

the zoom link entry should be at the last

This is what it currently pastes -

04-Aug-2021

Runs - 10


abc
User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Copy two items and paste them sequentially

04 Aug 2021, 10:53

This is just a demo to show you how to change the contents of the clipboard. You would use your own starting clipboard contents instead of the "abc" demonstration text.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Copy two items and paste them sequentially

04 Aug 2021, 10:58

I did not see the first line of the code

which is why I was wondering how "abc" found its way into clipboard

I will try it once again and update you


So what should be done to get zoom link into clipboard ?

"clipboard ="

that's it ?
User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Copy two items and paste them sequentially

04 Aug 2021, 11:00

Since you indicated that you have copied the Zoom link to the clipboard, you can use line 4 from my script to add to the clipboard contents.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Copy two items and paste them sequentially

04 Aug 2021, 11:07

I don't understand

Can you please tell me how to do that ?

How to give a reference to the link zoom has copied ?
User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Copy two items and paste them sequentially

04 Aug 2021, 11:13

I am working with your description:
I want ahk to 1.First enter the current date ( in the format - 04-Aug-2021); 2.copy any other text of my choice (this I will do manually); 3.and on sending ctrl v, the date should get entered, msgbox contents should get pasted first, a gap of two lines should be given and then the text that I would have copied should get pasted
If you set a hotkey to execute line 4 from what I posted-- put the hotkey below your auto-execute section-- then your description should be met at that point.

Code: Select all

F3::Clipboard = %A_DD%-%A_MMM%-%A_YYYY%`n`nRuns - %runs%`n`n`n%Clipboard%
I know nothing about copying a Zoom link, but you indicated that you would be doing that manually.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Copy two items and paste them sequentially

04 Aug 2021, 11:36

After the zoom meeting is started, there is an option in zoom to auto copy the link

Code: Select all

MouseClick, left, 637, 706
Send, ^v
Sleep 1000
Send, {Enter}
Sleep 1000
This above code pastes the pre copied zoom link into the chat

With your code , the current date and the number of runs are copied after the zoom link is copied ( the code that enters the pre copied zoom link is before your code which copies the current date and number of runs)


Now , as I understand

the zoom link is the first entry to the windows clipboard ( zoom auto copies the link)

current date is the second entry ( your code copies current date...)

number of runs is the third entry (.... and number of runs)


this being said , how to rearrange that order to -

date
number of runs
zoom link

is there a way to do that ?
User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Copy two items and paste them sequentially

04 Aug 2021, 18:55

Possibly:

Code: Select all

F3::
Clipboard =
Click, 637 706
ClipWait, 0
If ErrorLevel
 MsgBox, 48, Error, An error occurred while waiting for the clipboard.
Else SendInput %A_DD%-%A_MMM%-%A_YYYY%`n`nRuns - %runs%`n`n`n%Clipboard%{Enter}
Return
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Copy two items and paste them sequentially

04 Aug 2021, 20:01

The msgbox is displaying an error message
User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Copy two items and paste them sequentially

04 Aug 2021, 20:03

I do not have a way to test this. If the click is supposed to copy something to the clipboard, and it is not doing that, then you may need to check the coordinates and do some debugging to understand what is happening to the clipboard-- when is copying occurring, and what is being copied. If you already have a way to copy something to the clipboard, then you can eliminate those lines and just use the Send line as I mentioned earlier.

What the SendInput line does: sends your text and variables (date & runs), followed by the contents of your clipboard, and Enter.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Copy two items and paste them sequentially

04 Aug 2021, 22:48

I am taking it step by step

Code: Select all

Clipboard = abc
runs = 99
Clipboard = %A_DD%-%A_MMM%-%A_YYYY%`n`nRuns - %runs%`n`n`n%Clipboard%
Sleep, 100
let us leave the zoom link part of it

for this example say I am copying a text ( a random text every time)

what should the first line of the code "clipboard" be equal to ?
User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Copy two items and paste them sequentially

04 Aug 2021, 23:04

It appears that we are going in circles here. If you are copying text manually, you need just the following.

Code: Select all

F3::SendInput %A_DD%-%A_MMM%-%A_YYYY%`n`nRuns - %runs%`n`n`n%Clipboard%
You can test it in Notepad to see how it works. Run the script. Copy some text. Press F3. Runs is undefined here, but you can define it as you need.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Copy two items and paste them sequentially

05 Aug 2021, 00:07

First of all, it is working in the notepad

i.e
Date
Runs
Zoom link

are getting pasted.


When it comes to the chat service,

after entering the date and the number of runs, it is getting automatically sent

and then in the place where we type, the zoom link is getting pasted ( on pressing enter, the link gets sent)

essentially , three texts are being sent

1 date
2 runs

these two are getting pasted and sent without me pressing enter

3 the zoom link,

this gets pasted and on pressing enter , it gets sent.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Copy two items and paste them sequentially

05 Aug 2021, 00:51

After running the code and observing , this is what I have understood

" 'n " give a gap of one line

i.e it presses the enter key

once enter key is getting pressed , the chat service is sending the text

to give a gap of one line , enter key should be pressed while holding the shift key


so I have changed the code to this

Code: Select all

^d::

SendInput %A_DD%-%A_MMM%-%A_YYYY% +{enter} +{enter}Runs - %runs% +{enter} +{enter} +{enter} %Clipboard%
and it seem to be working
User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Copy two items and paste them sequentially  Topic is solved

05 Aug 2021, 06:40

Good to hear. Thank you for the update. You can try the following, too.

Code: Select all

^d::SendInput %A_DD%-%A_MMM%-%A_YYYY%+{Enter 2}Runs - %runs%+{Enter 3}%Clipboard%

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada and 84 guests