Click on the outlook calendar by searching the calendar Image (_ImageSearch) - autoit

I am using Imagesearch.au3 to search the calendar image on outlook . Below is the code .
Created a new folder --> ImageSearch.au3 , ImageSearchDLL.dll , and the screenshot of the calendar is placed
#include <ImageSearch.au3>
$x=0
$y=0
start()
while 1
sleep(1000)
WEnd
Func Start()
while 1
$result = _ImageSearch("cal.png",1,$x,$y,0)
if $result=1 Then
ConsoleWrite("Sucesfull")
MouseMove($x,$y,10)
Else
ConsoleWrite("Img not found")
EndIf
WEnd
EndFunc
Problem : Throws an error message
"C:\Users...\Desktop\AutoIT\New folder\img\ImageSearch.au3" (44) : ==> Subscript used on non-accessible variable.:
if $result[0]="0" then return 0
if $result^ ERROR

The dll will not load while running as a script. I'm not sure why but it seems others have the same problem. I was able to compile the script as a 64 bit application and then the application loaded the DLL. After changing the tolerance, I was able to find the image.
Also, I would rewrite your code. You have two infinite while loops for no reason. I added a sleep to the remain while loop. I would increase the tolerance.
#include <ImageSearch.au3>
start()
Func Start()
while 1
$x=0
$y=0
$result = _ImageSearch("cal.png",1,$x,$y,20)
if $result=1 Then
MsgBox(0,"Found Image","moving mouse")
MouseMove($x,$y,10)
Else
MsgBox(0,"Img not found","not found")
EndIf
sleep(10000)
WEnd
EndFunc
I tested with the 64bit imagesearch located at http://www.autoitscript.com/forum/topic/148005-imagesearch-usage-explanation/page-2

Related

Why Function "if ProcessExist" Don't Work in Others Computers

I'm trying to execute an IF ProcessExist.
in my win 10 64bit computer it works, but when i execute in other PC with win 7 or even with win 10. It do not execute.
#AutoIt3Wrapper_UseX64=N
If ProcessExists ("program.exe") Then
MsgBox ("", "Hold", "Test", 10)
Exit
Else
#RequireAdmin
Run(#ComSpec & " /c " & "C:\folder\file.bat", "", #SW_HIDE)
EndIf
Keep getting as if program.exe exist, but it's not.
#RequireAdmin must be on the very top of your script.
I assume it's not working when you compile the executable. It's probably called program.exe and it's finding its own process.
As for the Singleton see this:
_Singleton ( $sOccurrenceName [, $iFlag = 0] )
Enforce a design paradigm where only one instance of the script may be running
Example
#include <Misc.au3>
#include <MsgBoxConstants.au3>
If _Singleton("test", 1) = 0 Then
MsgBox($MB_SYSTEMMODAL, "Warning", "An occurrence of test is already running")
Exit
EndIf
MsgBox($MB_SYSTEMMODAL, "OK", "the first occurrence of test is running")

RF-AutoIT: Cant upload files in Chrome

I am trying to create a common exe for 3 browser based file upload using below code.
IE (Choose File to Upload),
Chrome (Open),
Firefox (File Upload)
This is working for IE but not for Chrome and FireFox. There is no error but its not showing given file along with path.
I will be using this .exe in my Robot Framework script.
#include <MsgBoxConstants.au3>
SelectWindowBasedOnTitle()
Func SelectWindowBasedOnTitle()
$winList = WinList()
$wTitle = CheckWindows($winList)
IF $wTitle == "Choose File to Upload" Then
IE()
ElseIf $wTitle == "Open" Then
Chrome()
Else
FireFox()
EndIf
EndFunc
Func CheckWindows($aArray)
For $i = 1 To Ubound($aArray) - 1
If WinActive($aArray[$i][1]) Then $wTitle= $aArray[$i][0] ;MsgBox(0, "Window Check", $aArray[$i][0] & " is active.")
Next
Return $wTitle
EndFunc
Func Example()
$wText = WinGetText("[ACTIVE]")
EndFunc
Func IE()
ControlFocus("Choose File to Upload","","Edit1")
ControlSetText("Choose File to Upload","","Edit1",$CmdLine[1])
ControlClick("Choose File to Upload","","Button1")
EndFunc
Func Chrome()
ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1",$CmdLine[1])
ControlClick("Open","","Button1")
EndFunc
Func FireFox()
ControlFocus("File Upload","","Edit1")
ControlSetText("File Upload","","Edit1",$CmdLine[1])
ControlClick("File Upload","","Button1")
EndFunc
This way i am using in my Robot script. Could you please help me understand is there a way to automate
${FileInfo} ${CURDIR}\\Xpaths.txt
${AutoIT} ${CURDIR}\\BrowserBasedWindowSelection.exe
Run Process ${AutoIT} ${FileInfo}

Capture and check bteq return code in Unix

I'm developing a script which in turn invokes several other scripts (.ksh). And basically when one of them fail they shouldn't proceed to the next one. So I tried checking for the return code in one script that involves bteq (Basic Teradata Query) session. Please find below the scenario:
bteq <<EOF!
.run file ${TGTRUNFILEN} ;
.maxerror 1;
.set width 245;
...
...
sel * from table ;
.if ACTIVITYCOUNT <> 0 then .GOTO QUIT
.os mail command "error msg"
exit 1;
.LABEL QUIT
.quit;
EOF!
echo $rcode
rcode=$?
if [[ $rcode != 0 ]]
then
echo "$0: Insufficient Perm Space : username " >&2
exit 4
fi
Here,the script fails and I can see the log saying failed with return code 1, but why isn't the text "$0:Insufficient Perm Space : Username" displayed. I think it exits the entire script, but I need this fixed somehow.
Can someone kindly help me on this?
Hi Thanks a ton for responding.I found a way to overcome this.I just added 'set' command like this.
set +e
bteq <<EOF!
...
...
EOF!
rcode=$?
set -e
Works fine for me.
Cheers

Killing a Haskell binary

If I press Ctrl+C, this throws an exception (always in thread 0?). You can catch this if you want - or, more likely, run some cleanup and then rethrow it. But the usual result is to bring the program to a halt, one way or another.
Now suppose I use the Unix kill command. As I understand it, kill basically sends a (configurable) Unix signal to the specified process.
How does the Haskell RTS respond to this? Is it documented somewhere? I would imagine that sending SIGTERM would have the same effect as pressing Ctrl+C, but I don't know that for a fact...
(And, of course, you can use kill to send signals that have nothing to do with killing at all. Again, I would imagine that the RTS would ignore, say, SIGHUP or SIGPWR, but I don't know for sure.)
Googling "haskell catch sigterm" led me to System.Posix.Signals of the unix package, which has a rather nice looking system for catching and handling these signals. Just scroll down to the "Handling Signals" section.
EDIT: A trivial example:
import System.Posix.Signals
import Control.Concurrent (threadDelay)
import Control.Concurrent.MVar
termHandler :: MVar () -> Handler
termHandler v = CatchOnce $ do
putStrLn "Caught SIGTERM"
putMVar v ()
loop :: MVar () -> IO ()
loop v = do
putStrLn "Still running"
threadDelay 1000000
val <- tryTakeMVar v
case val of
Just _ -> putStrLn "Quitting" >> return ()
Nothing -> loop v
main = do
v <- newEmptyMVar
installHandler sigTERM (termHandler v) Nothing
loop v
Notice that I had to use an MVar to inform loop that it was time to quit. I tried using exitSuccess from System.Exit, but since termHandler executes in a thread that isn't the main one, it can't cause the program to exit. There might be an easier way to do it, but I've never used this module before so I don't know of one. I tested this on Ubuntu 12.10.
Searching for "signal" in the ghc source code on github revealed the installDefaultSignals function:
void
initDefaultHandlers(void)
{
struct sigaction action,oact;
// install the SIGINT handler
action.sa_handler = shutdown_handler;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
if (sigaction(SIGINT, &action, &oact) != 0) {
sysErrorBelch("warning: failed to install SIGINT handler");
}
#if defined(HAVE_SIGINTERRUPT)
siginterrupt(SIGINT, 1); // isn't this the default? --SDM
#endif
// install the SIGFPE handler
// In addition to handling SIGINT, also handle SIGFPE by ignoring it.
// Apparently IEEE requires floating-point exceptions to be ignored by
// default, but alpha-dec-osf3 doesn't seem to do so.
// Commented out by SDM 2/7/2002: this causes an infinite loop on
// some architectures when an integer division by zero occurs: we
// don't recover from the floating point exception, and the
// program just generates another one immediately.
#if 0
action.sa_handler = SIG_IGN;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
if (sigaction(SIGFPE, &action, &oact) != 0) {
sysErrorBelch("warning: failed to install SIGFPE handler");
}
#endif
#ifdef alpha_HOST_ARCH
ieee_set_fp_control(0);
#endif
// ignore SIGPIPE; see #1619
// actually, we use an empty signal handler rather than SIG_IGN,
// so that SIGPIPE gets reset to its default behaviour on exec.
action.sa_handler = empty_handler;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
if (sigaction(SIGPIPE, &action, &oact) != 0) {
sysErrorBelch("warning: failed to install SIGPIPE handler");
}
set_sigtstp_action(rtsTrue);
}
From that, you can see that GHC installs at least SIGINT and SIGPIPE handlers. I don't know if there are any other signal handlers hidden in the source code.

autoit- How to minimize windows open on ff.au3?

Here my code:
#Include <FF.au3>
_FFStart()
If _FFIsConnected() Then
$sStringToSearch = "www.google.com"
sleep (2000)
If _FFSearch($sStringToSearch) Then
; add a new tab with an URL
_FFWindowOpen("http://ff-au3-example.thorsten-willert.de/")
Sleep(1000)
_FFWindowOpen("www.msn.com")
Sleep(1000)
_FFWindowOpen("www.yahoo.com")
Sleep(1000)
_FFWindowOpen("google.com")
EndIf
Else
EndIf
According to the script, when I visit google, it would open the first link followed by the other links; now how do I have the windows minimized once they are open.
Also I keep getting ErrorstdOut any solutions to this?
Try WinSetState ( "title", "text", flag )
Here is the link for the api: http://www.autoitscript.com/autoit3/docs/functions/WinSetState.htm
A sample is :
WinSetState("Calculator", "", #SW_MINIMIZE )

Resources