I have an AutoIT script to open and scroll to end of PDF file by mouse action. By the number of times for scrolling is depended on the zoom percent and the number of pages. How do I determine the end of PDF file for configure the number of times for scrolling?
Below is the sample script. I fixed the number of times for scrolling is 15
Func OpenAllPDFFile($vardirectory)
If #error = 1 Then
MsgBox($MB_SYSTEMMODAL, "", "Path is invalid.", 2)
ElseIf #error = 4 Then
MsgBox($MB_SYSTEMMODAL, "", "No report(s) found.", 2)
ElseIf #error Then
MsgBox($MB_SYSTEMMODAL, "", "Fail to open report", 2)
Else
$FileArray = _FileListToArray($vardirectory, "*.pdf",1)
$NewFileArray = SortPDFFile($FileArray)
For $i = 0 To UBound($NewFileArray)-1
ShellExecute($vardirectory & "\" & $NewFileArray[$i])
ConsoleWrite("Opening pdf file: " & $NewFileArray[$i] & #CRLF)
if WinWaitActive($NewFileArray[$i]) Then
ConsoleWrite("Pdf file " & $NewFileArray[$i] & " is opened" & #CRLF)
WinSetState($NewFileArray[$i], "", #SW_MAXIMIZE)
Sleep($varSleep)
ControlClick($NewFileArray[$i], "", $varZoomPercent)
ControlSend($NewFileArray[$i], "", $varZoomPercent, $vPercent)
Send("{ENTER}")
Sleep($varSleep)
For $y = 0 To 15
If WinExists("[CLASS:AcrobatSDIWindow]") Then
MouseWheel($MOUSE_WHEEL_DOWN, 12)
Sleep($varSleepRead)
Else
ExitLoop
EndIf
Next
Else
ConsoleWrite("Could not find pdf file: " & #CRLF)
EndIf
WinClose("[CLASS:AcrobatSDIWindow]")
Next
EndIf
WinClose($varDUTPlot,"")
EndFunc
If you really just need to go to the end of the PDF I would use Page Down like this:
Send("{PGDN down}") # hold key down
Sleep(10000) # hold it for 10 sec
Send("{PGDN up}") # stop holding it
You can increase or lower the time just by editing the sleep time(in ms).
I don't know how to scale it with the PDF size.
If you know the pagecount it would be easy. ;)
$c = PAGES_IN_PDF
$t = $c * 200 # plan enough time for slow PCs
Sleep($t)
Related
I want to get text from a dialog box. I am getting the title from the dialog box using winGetTitle() function.
My code in autoit is as follows:
$pId = Run("C:/foldername/Dialogbox.exe")
Local $hWnd = WinWait("[CLASS:#32770]", "", 10)
Local $sTitle = WinGetTitle("[ACTIVE]")
; Display the window title.
ConsoleWrite($sTitle & #CRLF)
; changing control from the class containg title to the class containing the text.
Local $hSysTray_Handle = ControlGetHandle('[Class:#32770]', '', '[Class:SysListView32;Instance:1]')
Local $sText = WinGetText("[ACTIVE]")
Local $sTextnew = ControlGetText($hSysTray_Handle, "", $sText)
ConsoleWrite($sTextnew & #CRLF)
This returns only the title and not the text in the dialog box. #32770 is the main class of dialog box and title, text are in the different classes in basic control info in autoit.
I am new to autoit and don't know how to fetch the text from dialog box. Or should I use sikuli for this?
; Start Mp3tag if not running.
If Not ProcessExists('Mp3tag.exe') Then
Run('"C:\Program Files (x86)\Mp3tag\Mp3tag.exe"')
If #error Then Exit 1
EndIf
; Scans working directory for Mp3 files.
WinWaitClose('Reading directory', '', 5)
; Main window.
$hWnd = WinWait('Mp3tag')
; Get item count of 1st column from the listview.
For $i1 = 1 To 5
$iCount = ControlListView($hWnd, '', 'SysListView321', 'GetItemCount')
If $iCount Then
ConsoleWrite('Found ' & $iCount & ' items.' & #CRLF)
ExitLoop
EndIf
Sleep(1000)
Next
If Not $iCount Then
MsgBox(0x40000, #ScriptName, 'Count is 0')
Exit 1
EndIf
; Get text of each listview item in the 1st column.
For $i1 = 0 To $iCount -1
$sText = ControlListView($hWnd, '', 'SysListView321', 'GetText', $i1)
ConsoleWrite(StringFormat('%3d Text: %s', $i1, $sText) & #CRLF)
Next
I do not have "C:/foldername/Dialogbox.exe" to test with.
I do have Mp3tag which has a SysListView32 control.
ControlListView() can get text etc. from a ListView control.
The parameter GetItemCount will get the count of list items
and GetText will get text from each list item.
This is test output:
Found 15 items.
0 Text: 01 - Lively Up Yourself.mp3
1 Text: 02 - Soul Rebel.mp3
2 Text: 03 - Treat Yourself Right.mp3
3 Text: 04 - Rebels Hop.mp3
4 Text: 05 - Soul Almighty.mp3
5 Text: 06 - Kaya.mp3
6 Text: 07 - Trenchtown Rock.mp3
7 Text: 08 - Soul Shakedown Party.mp3
8 Text: 09 - Natural Mystic.mp3
9 Text: 10 - Fussing And Fighting.mp3
10 Text: 11 - African Herbsman.mp3
11 Text: 12 - Keep On Moving.mp3
12 Text: 13 - Go Tell It On The Mountain.mp3
13 Text: 14 - How Many Times.mp3
14 Text: 15 - Bonus Track.mp3
The list item number is on the left
and the list item text is on the right,
following Text:.
At a guess, the code to test your Dialogbox.exe with:
Run("C:\foldername\Dialogbox.exe")
$hWnd = WinWait("[CLASS:#32770]", "", 10)
; Allow time for SysListView321 to fully load.
Sleep(1000)
; Get the window title.
$sTitle = WinGetTitle("[ACTIVE]")
ConsoleWrite($sTitle & #CRLF)
; Changing control from the class containing title to the class containing the text.
$hLView = ControlGetHandle($hWnd, '', 'SysListView321')
; Get item count of 1st column from the listview.
$iCount = ControlListView($hWnd, '', $hLView, 'GetItemCount')
; Get text of each listview item in the 1st column.
For $i1 = 0 To $iCount -1
$sText = ControlListView($hWnd, '', $hLView, 'GetText', $i1)
ConsoleWrite(StringFormat('%3d Text: %s', $i1, $sText) & #CRLF)
Next
It could use some improvement even if it works.
I could use some help performing a database correction, in regards to date and time of pictures were taken.
Essentially, the research we perform entails taking many pictures and entering the picture information into a database (we automated this with Microsoft Access). However, I performed a random check of our database and found that several dates and times of the photos were incorrect, and I am attempting to correct this via R as I was unable to correct it via Access.
What I need to do is to is write a script that reads these data, and compiles a list of the date taken information for all photos (there are several thousand). So far the best thing that I've found is
file.info(list.files(
"E:/Whatcom Creek Project/Data/Seal photos/Discovery/Catalog/Phoca vitulina",
recursive = T))
However this returns a list of NA NA for all information. Also, if I manually select one image to run file.info on, it doesn't return date taken (see the picture for the data I am attempting to retrieve)
If anyone has any suggestions I am all ears. Thanks in advance!!
-Ian
enter image description here
maybe still of any use?
i saw this message. I solved this a long time ago (2011) with a very basic VB6 code. The job is still working, but it is not applicable to all '.jpg files'. It depends with what camera the picture has been taken, but mostly pictures taken from a smartphone and classic camera's are returning the date the picture has been taken (not usable for whatsapp images or edited images).
The code is here below, and it is very basic code (but i hope it still can help or give idea's, and ... any new idea's are welcome too) :
'Reading of "Date Picture Taken" from .jpg file
'-----------------------------------------------
Debug.Print ">>>>>==== Start Read of .jpg-file ===== "; Date; " ===== "; Time; " ====<<<<<"
X = 0
DatePictureTaken = ""
TimePictureTaken = ""
FOUNDdatum = False
SWdatum = False
TELdatum = 0
Foto = FOLDER & "\" & tabFileName(FotoNr)
Open Foto For Binary Access Read As #1
'get startposition of the field "date picture taken"
Do
X = X + 1
Get #1, X, MyByte ': Debug.Print Chr(MyByte);
DoEvents
If Chr(MyByte) = ":" Then
'Debug.Print
SWdatum = True
Get #1, X + 3, MyByte
'Debug.Print "x+03="; Chr(MyByte)
If Chr(MyByte) <> ":" Then SWdatum = False 'Debug.Print "x+03="; Chr(MyByte)
Get #1, X + 9, MyByte
'Debug.Print "x+09="; Chr(MyByte)
If Chr(MyByte) <> ":" Then SWdatum = False 'Debug.Print "x+09="; Chr(MyByte)
Get #1, X + 12, MyByte
'Debug.Print "x+12="; Chr(MyByte)
If Chr(MyByte) <> ":" Then SWdatum = False 'Debug.Print "x+12="; Chr(MyByte)
'if a ':' is on the 3 locations (found above) then it is a date!
If SWdatum _
Then
TELdatum = TELdatum + 1
End If
'the 3e date is the date the picture has been taken
If TELdatum = 3 _
Then
FOUNDdatum = True
X = X - 4
Exit Do
End If
X = X + 12
End If
Loop Until EOF(1) 'Or X = 32765
If FOUNDdatum = False Then Close 1: End
BPdatum = X
EPdatum = X + 9
BPuur = X + 11
EPuur = X + 15
For X = BPdatum To EPdatum
Get #1, X, MyByte
'Debug.Print Chr(MyByte)
If Chr(MyByte) <> ":" _
Then
' DatePictureTaken = DatePictureTaken & "/"
'Else
DatePictureTaken = DatePictureTaken & Chr(MyByte)
End If
Next X
For X = BPuur To EPuur
Get #1, X, MyByte
'Debug.Print Chr(MyByte)
If Chr(MyByte) <> ":" _
Then
' DatePictureTaken = DatePictureTaken & "/"
'Else
TimePictureTaken = TimePictureTaken & Chr(MyByte)
End If
Next X
'Debug.Print "Date Picture Taken = "; DATUM
tbxDatum.Text = DatePictureTaken
tbxUur.Text = TimePictureTaken
Close 1
End Sub
I have read many post but nothing really helped.
My question looks similar but bit different.
I have to change EPOC time to system time format.
data type = datetime
value= 20160630165419.634204+060
desired output
data type = datetime
value= 30/06/2016 16:54:19
as the EPOC value has digits after dot and the datatype is datetime , which makes it difficult to divide it by 10 in a loop and get ingteral value.
Please suggest solution for given input format only.
You can use this function WMIDateStringToDate for converting your date :
WScript.echo WMIDateStringToDate("20160227235343.000000+060")
WScript.echo WMIDateStringToDate("20160630165419.634204+060")
'************************************************************
Function WMIDateStringToDate(Mydate)
WMIDateStringToDate = CDate(Mid(Mydate, 5, 2) & "/" & _
Mid(Mydate, 7, 2) & "/" & Left(Mydate, 4) _
& " " & Mid (Mydate, 9, 2) & ":" & _
Mid(Mydate, 11, 2) & ":" & Mid(Mydate,13, 2))
End Function
'************************************************************
Step 1: use DateSerial() and TimeSerial() on numbers (CInt()) extracted from your input (Mid()) to get a variant of subtype Date
Step 2: use SetLocale() and Replace() to format/stringify the Date
>> SetLocale "de-de"
>> sX = "20160630165419.634204+060"
>> dtD = DateSerial(CInt(Mid(sX, 1, 4)), CInt(Mid(sX, 5, 2)), CInt(Mid(sX, 7, 2)))
>> dtT = TimeSerial(CInt(Mid(sX, 9, 2)), CInt(Mid(sX, 11, 2)), CInt(Mid(sX, 13,2)))
>> dtX = dtD + dtT
>> WScript.Echo dtX, TypeName(dtX)
>> WScript.Echo Replace(dtX, ".", "/")
>>
30.06.2016 16:54:19 Date
30/06/2016 16:54:19
Danger, Will Robinson! Look at this test script:
Function WMIDateStringToDate(Mydate)
WMIDateStringToDate = CDate(Mid(Mydate, 5, 2) & "/" & _
Mid(Mydate, 7, 2) & "/" & Left(Mydate, 4) _
& " " & Mid (Mydate, 9, 2) & ":" & _
Mid(Mydate, 11, 2) & ":" & Mid(Mydate,13, 2))
End Function
'************************************************************
For Each sLocale In Split("de-de en-us")
SetLocale sLocale
For Each sDate In Split("20160227235343.000000+060 20160203235343.000000+060")
On Error Resume Next
dtX = WMIDateStringToDate(sDate)
If Err.Number Then dtX = Err.Description
On Error GoTo 0
WScript.Echo GetLocale(), sD, sDate, dtX
Next
Next
and its output:
cscript 38249865.vbs
1031 20160227235343.000000+060 27.02.2016 23:53:43
1031 20160203235343.000000+060 02.03.2016 23:53:43
1033 20160227235343.000000+060 27.02.2016 23:53:43
1033 20160203235343.000000+060 03.02.2016 23:53:43
to see the reason for:
The sample scripts are not supported under any Microsoft standard
support program or service. The sample scripts are provided AS IS
without warranty of any kind. Microsoft further disclaims all implied
warranties including, without limitation, any implied warranties of
merchantability or of fitness for a particular purpose. The entire
risk arising out of the use or performance of the sample scripts and
documentation remains with you. In no event shall Microsoft, its
authors, or anyone else involved in the creation, production, or
delivery of the scripts be liable for any damages whatsoever
(including, without limitation, damages for loss of business profits,
business interruption, loss of business information, or other
pecuniary loss) arising out of the use of or inability to use the
sample scripts or documentation, even if Microsoft has been advised of
the possibility of such damages.
(found here)
I have a problem with searching and displaying only the values that I need. So basically I need to get a class name stored in a variable which depends on the selected item.
Every [section] of items has key 1 ( item name ), 78 ( race ), 80 ( class ).
78=1 ; human - race
80=1 ; knight - class
80=2 ; archer - class
80=8 ; mage - class
78=2 ; orc - race
80=1 ; berskerer - class
80=2 ; hunter - class
80=8 ; sorc - class
78=4 ; elf - race
80=1 ; swashbuckler - class
80=2 ; ranger - class
80=8 ; elementalist - class
78=8 ; dragonscion - race
80=15 ; scion - class
Here is my code: http://pastebin.com/DUwhVAxY
Here is zip file with 2 images and .ini file http://uploaded.net/file/eleih11o.
In the 1st image is my code that works, and in the 2nd image is an example of what I need; just a variable with class name.
Here is one more image with all the stuff:
This is the closest I could get but still it will fail since you have no standard seperators and/or items.
Case $hFinddAllButton
GUICtrlSetData($hList, '')
Redim $afound[0][3]
Local $sCout = 0
Local $sCounterText[0]
Local $sCounterNum[0]
For $i = 0 To UBound($matches)-1
If StringInStr($matches[$i][2], GUICtrlRead($hSearchInput)) Then
_ArrayAdd($afound, $matches[$i][0] &'|'& $matches[$i][1] &'|'& $matches[$i][2])
ReDim $sCounterText[UBound($sCounterText) +1]
ReDim $sCounterNum[UBound($sCounterNum) +1]
$sCounterText[$sCout] = $matches[$i][2]
$sCounterNum[$sCout] = $matches[$i][0]
$sCout += 1
EndIf
Next
For $s = 0 To UBound($sCounterText) -1
;~ ConsoleWrite($sCounterText[$s] & #LF)
;~ _ArrayAdd($afound, $matches[$i][0] &'|'& $matches[$i][1] &'|'& $matches[$i][2])
Local $sSplit = StringSplit($sCounterText[0], " ", 2)
Local $sSplit2 = StringSplit($sCounterText[$s], " ", 2)
GUICtrlSetData($hList, '[' & $sCounterNum[$s] &'] ' & $sSplit[0] & " Biltz (" & GUICtrlRead($hSearchInput) & ") - " & $sCounterText[$s])
Next
Ok I am new with writing VBScript and I want to write a string of code that plays a file (WAV format) only on a certain day and only between specific times. After piecing together multiple fragments of code I found on the internet I was left with the following:
Dim myDateString
Dim thing1
thing1 = 0
myDateString = Date()
If myDateString < "13/08/13" Then
thing1 = 1
end if
if thing1 = 1 then
If myDateString > "15/08/13" Then
thing1 = 2
end if
end if
if thing1 = 2 then
hournow = hour(Time())
If hour(Time()) >= 9 And Hour(Now()) < 22 Then
set WshShell = CreateObject("WScript.Shell")
music = "C:\Users\MYUSERNAME\Desktop\MYSOUND.wav"
WshShell.Run "wmplayer """ & music & """",0,True
Else
wscript.quit 1
End If
Else
wscript.quit 1
End If
Ok so I had set this for the date I ran this on, within the hour I was in. But
it didn't work. I expected the VBS to start playing MYSOUND.wav but it didn't. When running the file
there were no errors though, so I was wondering what I did wrong!
I running Windows 7
If anyone could tell me what I did wrong, and how to fix it that would be great.
Double points if anyone could post a corrected version of the code!
Thanks to any answers!
First, indent your code and give your variables meaningful names!
Then, your date comparison doesn't work because you're trying to compare strings as if they were dates. This usually won't work (depending on your "system locale"): you need to use date type variables and an actual date comparison function (DateDiff in VBScript).
(EDIT: as Ansgar Wiechers pointed out, you don't need to use DateDiff to compare dates in VBScript, "DateStart <= Now And Now <= DateEnd" will do just fine)
Try this:
Dim DateStart, DateEnd, WshShell, music
DateStart = DateSerial(2013, 8, 13)
DateEnd = DateSerial(2013, 8, 15)
If DateDiff("D", DateStart, Now) >= 0 And DateDiff("D", Now, DateEnd) >= 0 Then
If Hour(Now) >= 9 And Hour(Now) < 22 Then
'*** delete after debugging ***
MsgBox "play sound"
Set WshShell = CreateObject("WScript.Shell")
music = "C:\Users\MYUSERNAME\Desktop\MYSOUND.wav"
'*** 2nd parameter : 0 hides wmplayer, 1 shows it ***
WshShell.Run "wmplayer """ & music & """", 1, True
Else
'*** delete after debugging ***
MsgBox "Not the right time"
End If
Else
'*** delete after debugging ***
MsgBox "Not the right day"
End If
Also, if you want to debug a small script like this, you can call MsgBox to do a simple tracking of what's actually executed (in your example, replacing your "WScript.Quit 1" by MsgBox would show you that the date is not properly compared.