Clipboard Issues

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
xbiged
Newbie
Posts: 2
Joined: Mon May 07, 2007 11:32 pm

Clipboard Issues

Post by xbiged » Thu May 10, 2007 3:44 am

I have been trying to automate some searches through my old accounting records. They are in pdf's (OCR'd) and are a few thousand pages long. I want to sort the output by dates hit.

Below is the full program. It might have a few confusing parts as I put in some long delays and even some "skips" to try to troubleshoot my problem. Not to mention all the trial and error of a newbie.

I was getting errors saying "unable to open clipboard" and errors in Adobe Acrobat including "error copying to clipboard. There was an internal error." If I do the cut manually it works fine - so long as MS is closed! If MS is open, I get the error, even when doing a manual Ctrl-C!

I've tried multiple ways (Ctrl-C and ALT-ec) to cut the text thru Acrobat, all with the same results.

I have a cut and clipboard read earlier in the script and it worked fine.

Can one of you gurus help?

Many Thanks,
Ed

//Ask User for the title of the search to be performed
Let>INPUT_BROWSE=0
input>searchname,Enter the title for this search:
input>delay,Enter relative file size:
//Reset variables to starting point
input>searchday,Enter day of month to start:
input>searchmonth,Enter month number to start:
input>searchmonthname,Enter month name to start:
input>searchyears,Enter year to start YY:
input>searchyearf,Enter year to start YYYY:
input>today,Enter day number to end:
input>tomonth,Enter month number to end:
input>toyear,Enter year to end YYYY:

//Open Adobe Acrobat
Let>RP_WINDOWMODE=3
Run Program>C:\Program Files\Adobe\Acrobat 8.0\Acrobat\Acrobat.exe
WaitWindowOpen>Adobe Acrobat*

//Open File Selection Window
Press CTRL
Send>o
Release CTRL
//Wait for user to select file
WaitWindowClosed>Open

//Wait for file to open

Wait>delay
SetFocus>Adobe Acrobat*
Wait>2
Press CTRL
send>0
Release CTRL
Press Shift
Press CTRL
send>f
Release CTRL
Release Shift
WaitWindowOpen>Search


Label>Start

//Field length used for adding leading zeros in search and file names

Length>searchyears,yrlen
Length>searchmonth,monlen
Length>searchday,daylen
Let>Con=0
If>{(%daylen%=1)AND(%monlen%=2)AND(%yrlen%=2)}
Let>Con=1
EndIf
If>{(%daylen%=2)AND(%monlen%=1)AND(%yrlen%=2)}
Let>Con=2
EndIf
If>{(%daylen%=2)AND(%monlen%=2)AND(%yrlen%=1)}
Let>Con=3
EndIf
If>{(%daylen%=1)AND(%monlen%=1)AND(%yrlen%=2)}
Let>Con=4
EndIf
If>{(%daylen%=1)AND(%monlen%=2)AND(%yrlen%=1)}
Let>Con=5
EndIf
If>{(%daylen%=2)AND(%monlen%=1)AND(%yrlen%=1)}
Let>Con=6
EndIf
If>{(%daylen%=1)AND(%monlen%=1)AND(%yrlen%=1)}
Let>Con=7
EndIf


//Build Date String for first search - Month D, YYYY
Let>SearchField={%searchmonthname%+" "+%searchday%+", "+%searchyearf%}
send>SearchField
Press Enter

//Wait for the Search window to automatically go into the background
WaitWindowChanged>delay
Wait>.25
GetActiveWindow>window_title,,,,
If>window_title=Search
Goto>SecondSearch
EndIf
Goto>ExtractSave


Label>SecondSearch

//Clear search field
SetFocus>Search
PushButton>Search,New Search
Wait>.25
Press Backspace
//Build Date String for second search - M/D/YY
send>%searchmonth%
send>/
send>%searchday%
send>/
If>{(%Con%=3)OR(%Con%=5)OR(%Con%=6)OR(%Con%=7)}
send>0
EndIf
send>%searchyears%
Press Enter

//Wait for the Search window to automatically go into the background
WaitWindowChanged>delay
Wait>.25
GetActiveWindow>window_title,,,,
If>window_title=Search
Goto>ThirdSearch
EndIf
Goto>ExtractSave


Label>ThirdSearch

//Build Date String for third search - M/D/YYYY
Let>SearchField={%searchmonth%+"/"+%searchday%+"/"+%searchyearf%}
//Clear search field and send new search string
SetFocus>Search
PushButton>Search,New Search
Wait>.25
Press Backspace
send>SearchField
Press Enter

//Wait for the Search window to automatically go into the background
WaitWindowChanged>delay
Wait>.25
GetActiveWindow>window_title,,,,
If>window_title=Search
Goto>FourthSearch
EndIf
Goto>ExtractSave


Label>FourthSearch

//Clear search window for new search string
SetFocus>Search
PushButton>Search,New Search
Wait>.25
Press Backspace
//send new search field - MM/DD/YY
//No need to send leading zero for month as search is more complete without leading zero in month
send>%searchmonth%
send>/
If>{(%Con%=1)OR(%Con%=4)OR(%Con%=5)OR(%Con%=7)}
send>0
EndIf
send>%searchday%
send>/
If>{(%Con%=3)OR(%Con%=5)OR(%Con%=6)OR(%Con%=7)}
send>0
EndIf
send>%searchyears%
Press Enter

//Wait for the Search window to automatically go into the background
WaitWindowChanged>delay
Wait>.25
GetActiveWindow>window_title,,,,
If>window_title=Search
Goto>FifthSearch
EndIf
Goto>ExtractSave


Label>FifthSearch

//Clear search window for new string
SetFocus>Search
PushButton>Search,New Search
Wait>.25
Press Backspace
//send new search field - MM/DD/YYYY
//If>{(%Con%=2)OR(%Con%=4)OR(%Con%=6)OR(%Con%=7)}
// send>0
// EndIf
send>%searchmonth%
send>/
If>{(%Con%=1)OR(%Con%=4)OR(%Con%=5)OR(%Con%=7)}
send>0
EndIf
send>%searchday%
send>/
send>%searchyearf%
Press Enter

//Wait for the Search window to automatically go into the background
WaitWindowChanged>delay
Wait>.25
GetActiveWindow>window_title,,,,
If>window_title=Search
Goto>EndSearch
EndIf
Goto>ExtractSave

Label>EndSearch

Gosub>AdvanceDy

//Reset search box for first search
SetFocus>Search
PushButton>Search,New Search
Wait>.3
Press Backspace

Goto>Start



///Subroutines Below///


SRT>AdvanceDy
If>{(%today%=%searchday%)AND(%tomonth%=%searchmonth%)AND(%toyear%=%searchyearf%)}
Goto>EndProgram
EndIf
Add>searchday,1
If>searchday=32
Gosub>AdvanceMn
EndIf
End>AdvanceDy


SRT>AdvanceMn
//Special section for Month Name field
If>searchmonthname=November
let>searchmonthname=December
EndIf
If>searchmonthname=November
let>searchmonthname=December
EndIf
If>searchmonthname=November
let>searchmonthname=December
EndIf
If>searchmonthname=October
let>searchmonthname=November
EndIf
If>searchmonthname=September
let>searchmonthname=October
EndIf
If>searchmonthname=August
let>searchmonthname=September
EndIf
If>searchmonthname=July
let>searchmonthname=August
EndIf
If>searchmonthname=June
let>searchmonthname=July
EndIf
If>searchmonthname=May
let>searchmonthname=June
EndIf
If>searchmonthname=April
let>searchmonthname=May
EndIf
If>searchmonthname=March
let>searchmonthname=April
EndIf
If>searchmonthname=February
let>searchmonthname=March
EndIf
If>searchmonthname=January
let>searchmonthname=February
EndIf

Add>searchmonth,1
If>searchmonth=13
Gosub>AdvanceYr
EndIf
Let>searchday=1
End>AdvanceMn


SRT>AdvanceYr
Add>searchyearf,1
Let>searchmonthname=January
Let>searchmonth=1
//Special section for double digit year field
Add>searchyears,1
If>searchyears=100
searchyears=0
EndIf
End>AdvanceYr


Label>ExtractSave
Label>ExtractTop

//Extract the page to save as a separate document
Wait>.5
Press ALT
send>dx
Release ALT
Wait>.75

//Skip put in to test clipboard
Goto>Skip

//Put page number to clipboard for use later
Press CTRL
send>c
Release CTRL


Label>Skip

Press Enter

Wait>2

//GetClipBoard>PageNum
//Ensure page is centered in window (so left click is on text)
Press CTRL
send>0
Release CTRL

Wait>2

//Highlight date hit and highlight in yellow
Press Shift
Press CTRL
send>f
Release CTRL
Release Shift
Wait>1
Press Enter
Wait>.5
Press ALT
send>tceh
Release ALT
Wait>.5

//Locate and pickup Goren number
//Reset Goren number if click and copy is not picked up
Let>GorenNum=0
//position mouse in lower right corner of document and click
MouseMove>1275,1108
LClick
Wait>1
Press End
Wait>1
//copy GOREN number to clipboard
Press Shift
Press Left*5
Release Shift
Press ALT
send>ec
Release ALT
Wait>10
GetClipBoard>GorenNum
Goto>EndProgram

//Standardize PageNumber format to 5 digits and generate new file name
Let>PageNum=12345
Length>PageNum,PageDigits
If>PageDigits=5
Let>Tempfilename={%searchyearf%+"-"+%searchmonth%+"-"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%}
If>monlen=1
Let>Tempfilename={%searchyearf%+"-0"+%searchmonth%+"-"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%}
EndIf
If>daylen=1
Let>Tempfilename={%searchyearf%+"-"+%searchmonth%+"-0"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%}
EndIf
If>{(%monlen%=1)AND(%daylen%=1)}
Let>Tempfilename={%searchyearf%+"-0"+%searchmonth%+"-0"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%}
EndIf
EndIf
If>PageDigits=1
Let>Tempfilename={%searchyearf%+"-"+%searchmonth%+"-"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 0000"+%PageNum%}
If>monlen=1
Let>Tempfilename={%searchyearf%+"-0"+%searchmonth%+"-"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 0000"+%PageNum%}
EndIf
If>daylen=1
Let>Tempfilename={%searchyearf%+"-"+%searchmonth%+"-0"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 0000"+%PageNum%}
EndIf
If>{(%monlen%=1)AND(%daylen%=1)}
Let>Tempfilename={%searchyearf%+"-0"+%searchmonth%+"-0"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 0000"+%PageNum%}
EndIf
EndIf
If>PageDigits=2
Let>Tempfilename={%searchyearf%+"-"+%searchmonth%+"-"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 000"+%PageNum%}
If>monlen=1
Let>Tempfilename={%searchyearf%+"-0"+%searchmonth%+"-"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 000"+%PageNum%}
EndIf
If>daylen=1
Let>Tempfilename={%searchyearf%+"-"+%searchmonth%+"-0"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 000"+%PageNum%}
EndIf
If>{(%monlen%=1)AND(%daylen%=1)}
Let>Tempfilename={%searchyearf%+"-0"+%searchmonth%+"-0"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 000"+%PageNum%}
EndIf
EndIf
If>PageDigits=3
Let>Tempfilename={%searchyearf%+"-"+%searchmonth%+"-"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 00"%PageNum%}
If>monlen=1
Let>Tempfilename={%searchyearf%+"-0"+%searchmonth%+"-"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 00"+%PageNum%}
EndIf
If>daylen=1
Let>Tempfilename={%searchyearf%+"-"+%searchmonth%+"-0"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 00"+%PageNum%}
EndIf
If>{(%monlen%=1)AND(%daylen%=1)}
Let>Tempfilename={%searchyearf%+"-0"+%searchmonth%+"-0"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 00"+%PageNum%}
EndIf
EndIf
If>PageDigits=4
Let>Tempfilename={%searchyearf%+"-"+%searchmonth%+"-"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 0"+%PageNum%}
If>monlen=1
Let>Tempfilename={%searchyearf%+"-0"+%searchmonth%+"-"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 0"+%PageNum%}
EndIf
If>daylen=1
Let>Tempfilename={%searchyearf%+"-"+%searchmonth%+"-0"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 0"+%PageNum%}
EndIf
If>{(%monlen%=1)AND(%daylen%=1)}
Let>Tempfilename={%searchyearf%+"-0"+%searchmonth%+"-0"+%searchday%+" "+%searchname%+" GOREN "+%GorenNum%+" Page 0"+%PageNum%}
EndIf
EndIf
//Wait for the new window to open
WaitWindowOpen>Pages from*
Wait>.5

//Write hit line to log file
WriteLn>C:\%searchname%.log,,%Tempfilename%

//Check to see if file exists, already
IfFileExists>%Tempfilename%
Goto>Recycle
EndIf

//Log entry with comma separated values
Let>logentry=%searchyearf%,%searchmonth%,%searchday%,%searchname%,%GorenNum%
WriteLn>C:\%searchname%.csv,,%logentry%

//Add Footer lower left
Press ALT
send>dha
Release ALT
WaitWindowOpen>Add Header and Footer
Wait>4.2
MouseMove>639,499
LClick
send>%Tempfilename%
Wait>.5
Press ALT
send>o
Release ALT
WaitWindowClosed>Add Header and Footer
Wait>.25

//Open the save as Dialog
Press Shift
Press CTRL
send>s
Release CTRL
Release Shift
WaitWindowOpen>save as
Wait>.1

//Remove default file name
Press Backspace
//Create file name and send to dialog window
send>%Tempfilename%
Press Enter
WaitWindowClosed>save as
Wait>.25
SetFocus>Adobe*
Wait>.25

Label>Recycle

Press CTRL
send>w
Release CTRL
Wait>.25
send>n
Wait>.25

SetFocus>Search
Wait>.4
Press Down
Wait>.4
GetActiveWindow>window_name,,,,
If>window_nameExtractTop
EndIf
Goto>EndSearch

Label>EndProgram
SetFocus>Adobe Acrobat*
Press ALT
Press F4
Release ALT

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu May 10, 2007 6:57 am

Before we take a more detailed look at your script, which version of Macro Scheduler are you using? Do you have the latest (9.1.02) and have you checked the history: http://www.mjtnet.com/mswhatsnew.htm
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

xbiged
Newbie
Posts: 2
Joined: Mon May 07, 2007 11:32 pm

Post by xbiged » Thu May 10, 2007 8:47 pm

I'm not at the computer with the program but I'm sure it's up-to-date. I reveived it just a week or two ago.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu May 10, 2007 8:53 pm

Version 9.1 was released within the last couple of weeks, so you might not have the latest version.

As well as make sure you have the latest version you should use WaitClipBoard in your script before any clipboard operations to ensure it waits until the clipboard is free.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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