If clipboard contains something, then...

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
zopita
Newbie
Posts: 19
Joined: Wed Feb 18, 2009 5:45 pm
Location: Spain

If clipboard contains something, then...

Post by zopita » Thu Oct 29, 2009 12:36 pm

Hi,

I need this code: "If clipboard contains "aaaaaa", then stop, else continus to execute the macro.

I'm not able to make this :oops: . ¿Does someone help me?

¡Thanks!

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Oct 29, 2009 1:10 pm

More information would be helpful. What are you trying to do?

Are you looking for a way to check the clipboard during a loop in your script? Or does this need to work the moment the test string enters the clipboard? If the former, just place the following in your script in an appropriate spot.

Code: Select all

GetClipBoard>data
If>data=aaaaaa
  Exit>0
EndIf
If the latter, it gets a little more complicated. there are no event handlers in Macro Scheduler to directly detect clipboard contents and then act on the contents. That said you could do just that by being a little creative.

You could write the above code lines to a secondary script and insert above the Exit>0 line a Writeln> that creates a file to be detected by the "file_exists". Something like.

Code: Select all

OnEvent>file_exists,%temp_dir%scratchFile.tmp,0,CloseScript

SRT>CloseScript
  DeleteFile>%temp_dir%scratchFile.tmp
  DeleteFile>%temp_dir%scratchFile.scp
  Exit>0
END>CloseScript


WriteLn>%temp_dir%scratchFile.scp,wres,Label>Start
WriteLn>%temp_dir%scratchFile.scp,wres,GetClipBoard>data
WriteLn>%temp_dir%scratchFile.scp,wres,If>data=aaaaaa
WriteLn>%temp_dir%scratchFile.scp,wres,  WriteLn>%temp_dir%scratchFile.tmp,Wres,1
WriteLn>%temp_dir%scratchFile.scp,wres,  Exit>0
WriteLn>%temp_dir%scratchFile.scp,wres,EndIf
WriteLn>%temp_dir%scratchFile.scp,wres,Wait>0.01
WriteLn>%temp_dir%scratchFile.scp,wres,goto>Start

ExecuteFile>%temp_dir%scratchFile.scp

////the rest of your code
so what do you need?



Here's a working sample:

Code: Select all

OnEvent>file_exists,%temp_dir%scratchFile.tmp,0,CloseScript

SRT>CloseScript
  DeleteFile>%temp_dir%scratchFile.tmp
  DeleteFile>%temp_dir%scratchFile.scp
  Exit>0
END>CloseScript


WriteLn>%temp_dir%scratchFile.scp,wres,Label>Start
WriteLn>%temp_dir%scratchFile.scp,wres,GetClipBoard>data
WriteLn>%temp_dir%scratchFile.scp,wres,If>data=aaaaaa
WriteLn>%temp_dir%scratchFile.scp,wres,  WriteLn>%temp_dir%scratchFile.tmp,Wres,1
WriteLn>%temp_dir%scratchFile.scp,wres,  Exit>0
WriteLn>%temp_dir%scratchFile.scp,wres,EndIf
WriteLn>%temp_dir%scratchFile.scp,wres,Wait>0.01
WriteLn>%temp_dir%scratchFile.scp,wres,goto>Start

ExecuteFile>%temp_dir%scratchFile.scp

Dialog>Dialog1
   Caption=Counting
   Width=445
   Height=250
   Top=148
   Left=27
   Label=msLabel1,168,112
EndDialog>Dialog1
show>Dialog1

Let>kk=0
Label>Loop
 Add>kk,1
 Let>dialog1.mslabel1=%kk%
 ResetDialogAction>dialog1
 Wait>0.01
goto>Loop

zopita
Newbie
Posts: 19
Joined: Wed Feb 18, 2009 5:45 pm
Location: Spain

Macro stops when clipboard contens something

Post by zopita » Fri Oct 30, 2009 5:33 am

Hi JRL,

I have Doc1.doc with 150 lines. The macro must cut the first line, to jumps to Doc2.doc, search this line and delete it. Then, jumps to Doc1.doc and repeats.

I have make the macro and it works well but I will like that the macro stops al the end of Doc1.doc. So, if I add at the end of Doc1.doc a line like "aaaaaa", the macro stops when Macro Scheduler detects that clipboard contents is "aaaaaa".

Thanks for your help :)

zopita
Newbie
Posts: 19
Joined: Wed Feb 18, 2009 5:45 pm
Location: Spain

¡¡¡Thanks, JRL!!!

Post by zopita » Sat Oct 31, 2009 6:28 am

Code: Select all

GetClipBoard>data
If>data=aaaaaa
  Exit>0
EndIf

Hi JRL,
This simple code is perfect for my macro. Thanks!!! :D

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts