if check not working as intended

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
PaperTronics
Posts: 3
Joined: 10 Jul 2018, 03:40

if check not working as intended

10 Jul 2018, 03:53

Code: Select all

FormatTime, Time, , h:mm tt

if Time >= 7:00 PM
{
	Run, C:\Users\UserNameThatImTooShyToPostHere\AppData\Local\FluxSoftware\Flux\flux.exe
}

else Runwait, taskkill /im flux.exe
Hello fellow humans. I'm kind of new to autohotkey, although I do have programming experience. My problem is that the above code, does not work as I desire it to. What I want it do is, start f.lux at 7:00 PM or greater than 7:00PM, and close it if it's less than 7:00PM. I tested this script out by changing my clock time, and it only works when I start it again and again. For example, if the script has been running since 2 hours, and it's 7:00PM now, then it won't start f.lux, it will only start f.lux when I restart/refresh it. That's the best way I could explain it in. I know I suck at explaining things so I hope you understood what I'm going for here.

Any help is appreciated,
PaperTronics
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: if check not working as intended

10 Jul 2018, 05:14

"close it if its less than 7 pm". what do u mean by this? 10pm the previous day is less than 7pm the next day, so flux should never run then?

Code: Select all

#NoEnv
#SingleInstance Force

path := "C:\Users\UserNameThatImTooShyToPostHere\AppData\Local\FluxSoftware\Flux\flux.exe"
SplitPath path, exe
SetTimer CheckFlux, 1000
Return

CheckFlux:
	FormatTime hour, A_Now, H

	if (hour >= 19 && hour <= 24)
	{
		if !WinExist("ahk_exe" exe)
			Run % path
	}
	else
		Process Close, % exe
Return
Last edited by swagfag on 10 Jul 2018, 07:05, edited 1 time in total.
Ridwan
Posts: 144
Joined: 17 Oct 2015, 21:06
Location: Indonesia

Re: if check not working as intended

10 Jul 2018, 06:00

Don't know why, but after i test swagfag code to my own program, it open new window multiple time, even after the window already exist.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: if check not working as intended

10 Jul 2018, 07:05

forgot brackets, fixed now
PaperTronics
Posts: 3
Joined: 10 Jul 2018, 03:40

Re: if check not working as intended

11 Jul 2018, 10:44

Sorry for the late response, but swagfag, your solution opens the flux window every 1 second which obviously is annoying and not desired. Also, yes, 10pm the next day is less than 7pm the previous day, but 10pm the next day is more than 7pm that day, so the program runs.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: if check not working as intended

11 Jul 2018, 11:08

maybe flux doesnt possess any detectable windows, try #DetectHiddenWindows On. Failing that, you can replace winexist with Process Exist, ur_process_name and check the ErrorLevel
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: if check not working as intended

11 Jul 2018, 12:41

I had these lines for f.lux which may work:

Code: Select all

DetectHiddenWindows, On
if WinExist("f.lux ahk_class ytWindow") ;normal
|| WinExist("F.Lux ahk_class ytWindow") ;portable
	MsgBox, % "exists"
else
	MsgBox, % "doesn't exist"
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
PaperTronics
Posts: 3
Joined: 10 Jul 2018, 03:40

Re: if check not working as intended

12 Jul 2018, 08:42

Code: Select all

FormatTime, Time, , h:mm: tt
DetectHiddenWindows, On
if WinExist("f.lux ahk_class ytWindow") if Time >= 7:00 PM
|| WinExist("F.Lux ahk_class ytWindow") 
	
else
	MsgBox, % "doesn't exist"

return
This code works. I don't know how, or why it works, but it just does. I was experimenting with some code that you all sent, and got so frustrated over this I left the editor and continued with my normal work. But then, it was 7:00 PM and flux automatically opened. I changed the time again to something like 1:30 PM and flux automatically shut down. This is simply a miracle for me. Thanks for all of your help. Really awesome community here.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Joey5 and 305 guests