Page 1 of 1

I hope Someone Can Commentoon My Code Errors

Posted: 28 Aug 2017, 10:46
by BillW
I'm new at this! I have written several little test scripts and have them working. Now I'm working on the little routine that I really need to use and I'm still very unclear on a lot of syntax issues and my script is not working. I'm hoping someone will be kind enough to point out my errors. Here is the current state of my routine:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force

^m::
Loop
{
	Sleep 500
	MsgBox Loop Cnt is "%A_Index%".
	if A_Index > 9 
	{
		ExitApp
	}
	WinGetTitle, Title, A
	MsgBox Active Window is "%Title%"
}
until Title := "C:\Users\BillWilson\Temp\Test1"

; Found it; Close it
WinKill "C:\Users\BillWilson\Temp\Test1"

return

Re: I hope Someone Can Commentoon My Code Errors

Posted: 28 Aug 2017, 11:01
by Gio
Hello BillW.

Welcome to the AutoHotkey community forums.

This line:

Code: Select all

until Title := "C:\Users\BillWilson\Temp\Test1"
Is using an expression assignment operator (:=), which does not serve as a comparisson operator.

Use the regular equals (=) operator whenever you wish to compare values. It is also a good idea to enclose your comparissons between parenthesis.

Code: Select all

until (Title = "C:\Users\BillWilson\Temp\Test1")
If something else is not to your design, please provide more in-depth feedback about how the routine should behave.

Best wishes.

Re: I hope Someone Can Commentoon My Code Errors

Posted: 28 Aug 2017, 15:12
by BillW
Thanks for the correction Gio. The routine is still not doing all that I need done so let me explain what my objective is.

I have volunteered to maintain 2 laptop computers at my church. Since I don't live next door to the church I have been experimenting with using Team Viewer to remotely connect to each of those computers to see if updates are pending and to see if they are running OK. The problem is that when I disconnect Team Viewer from either of those computers it pops up a message box as it disconnects. The message box says something about my using the free version of Team Viewer. One of the computers is used to run a full-time display in the church-office lobby so I can't leave it with some message being displayed on top of the display that is intended for that message board. So, my objective is to initiate an AutoHotKey routine just before disconnecting Team Viewer and have that routine look for and close the pop up message and then close itself.

In it current state, the AutoHotKey routine is finding the message box (named "Test1" right now) but it is not closing it. I should point out that the window I'm trying to close in my testing at home right now is a File Explorer window. I have manually created a sub-folder named Test1 and I have assumed that WinKill is able to close it. If that is not possible then that may be my current problem!

Thanks,
Bill

Re: I hope Someone Can Commentoon My Code Errors

Posted: 28 Aug 2017, 17:00
by obeeb
The following should close the team viewer message box:

Code: Select all

settimer closeTeamNag

return

closeTeamNag:
	WinWaitActive, Sponsored session
	send, {enter}
return

Re: I hope Someone Can Commentoon My Code Errors

Posted: 28 Aug 2017, 18:51
by BillW
WOW obeeb! That is certainly simple! Unfortunately, there is one case that I haven't mentioned that still needs to be accounted for: I have noticed while testing my use of Team Viewer at home that sometimes the popup message does not show up! I don't know why but I expect it is related to what activity I performed or didn't perform while connected. So, I intended my code to give up and exit if it did not find the popup message over a small period of time. Is there a simple change to your code that will account for this situation in case it comes up?

I really appreciate your suggestion.
Bill

Re: I hope Someone Can Commentoon My Code Errors

Posted: 28 Aug 2017, 18:58
by obeeb
Sure, what I wrote is something you can run and just keep it running and it will close this message box when it will appear. How do you want to use it?

Re: I hope Someone Can Commentoon My Code Errors

Posted: 28 Aug 2017, 19:35
by BillW
I was planning on only running my routine when it was needed, as I close a remote connection in Team Viewer. I'm am generally not in favor of running something all the time just in case it might be needed. I realize your routine won't use much, if any, resources while it is running but the idea of leaving it running just does not appeal to me.

Thank for your help.
Bill

Re: I hope Someone Can Commentoon My Code Errors

Posted: 28 Aug 2017, 21:30
by obeeb
ok, then you can just wait for let's say 10 seconds and exit the script if there is no message

Code: Select all

closeTeamNag:
	WinWaitActive, Sponsored session, , 10
	if (!ErrorLevel)
		send, {enter}
	ExitApp
return

Re: I hope Someone Can Commentoon My Code Errors

Posted: 28 Aug 2017, 22:18
by BillW
Thanks obeeb. That should keep me satisfied and the whole thing is still very nice and short.

Bill

Re: I hope Someone Can Commentoon My Code Errors

Posted: 29 Aug 2017, 10:43
by BillW
When I use the SciTE4AutoHotkey script editor to create a new script it automatically adds the following lines at the beginning of the script:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
Should those lines be included in the file that contains the script suggested in the earlier posts in this thread? I'm not clear when those code lines are important in a script.

Thanks,
Bill

Re: I hope Someone Can Commentoon My Code Errors

Posted: 29 Aug 2017, 14:51
by obeeb
Yes, they are just recommended defaults, leave them and put the actual script below.

Re: I hope Someone Can Commentoon My Code Errors

Posted: 29 Aug 2017, 14:59
by BillW
Thanks!
Bill

Re: I hope Someone Can Commentoon My Code Errors

Posted: 05 Sep 2017, 15:46
by BillW
obeeb wrote:The following should close the team viewer message box:

Code: Select all

settimer closeTeamNag

return

closeTeamNag:
	WinWaitActive, Sponsored session
	send, {enter} 
return
I'm back on this subject after some interruptions! The code above is your original suggestion which is supposed to run all the time. I had tried to use your latest version of this script that does not run all the time and it did not seem to do anything so I have switched to the one shown above. It also does not close the window with the "Sponsored session" title. I have another little scrip that simply displays the title of the active window and it says that the window I want to close does have that title.

1. Is there some way to see that a script is in fact running, i.g. maybe in the Task Manager?

2. Am I correct in assuming that clicking on the Run button in the Scrip Editor is a valid way to activate a script?

3. Any other suggestions at this point?

Thanks,
Bill