bunsen_h: (Default)
[personal profile] bunsen_h
I sometimes have trouble getting off my computer at night. Or, more to the point, staying off it.  There's always something I'll want to look up when I'm getting to bed.

I wrote a little program for my old machine that would fill its monitor with a full-screen window in obnoxious colours with a big message, telling me to go to bed. I made it as "stubborn" as I could, though there were still ways to minimize it. It was triggered as a scheduled task to go off every 10 minutes from 10 p.m. to 10:30, then every 5 minutes to midnight, then every 2 minutes until around 1 a.m.; every time it was triggered, it would stay up for a minute. The intention was to be annoying without making it completely impossible to look something up if it was really important.

It wasn't as effective as I'd have liked, because it was possible to make the nag go away -- too easy, really. And it didn't run under more recent versions of Windows.

So I've come up with a better version, which should run under any versions of Windows. It's a script using the AutoHotkey "language". One can change a variety of options: the message text, the colours, etc., as well as set whether it should be stubborn about keeping its windows in place.  The configurable options are at the top of the file.

Please feel free to try it, and let me know what you think. All you should need to do is install AutoHotkey, copy the following text into a file with the extension ".ahk", and run the script.

; Name: goto_bed.ahk
; Version: 1.0
; Type: AutoHotkey script
; Author: Joel Polowin, 2017 May 19
; Function: Opens a full-screen window in each monitor displaying a large
; text message, pauses, then closes all of its windows and exits. Intended
; to "nag" to get one to stop using the computer, run as a scheduled task.
; ------
; Configurable options:
Window_text := "Go to bed!" ; Message to show in windows
Duration_in_s := 60 ; Time for the windows to stay up, in s
Text_size := 180 ; Text font size
Stubborn := false ; If true, will disable the "minimize" and "close" icons so
; the script can only be halted through the task manager!

; Background and text colours, in quotes: one of Black, Silver, Gray, White,
; Maroon, Red, Purple, Fuchsia, Green, Lime, Olive, Yellow, Navy, Blue, Teal,
; or Aqua. Or a 6-digit RGB hexadecimal value; e.g., FFA022 is light orange.
Window_colour := "FF1111"
Text_colour := "Green"

; ------
#SingleInstance force ; Cancel any copies of this script already running
SysGet, monitor_count, MonitorCount ; Get the # of monitors

; Here's where we create the windows
Loop, %monitor_count% ; Loop over the monitors
{
SysGet, monitor_, Monitor, %A_Index% ; Get the coords of a monitor
PopWindowName := "window" . A_Index ; Create a name for a window
; Create the window, recording its unique ID
Gui, %PopWindowName%:New, +HwndWindowID, %Window_text%
WinIDs%A_Index% := WindowID ; store the window's ID
; If the "stubborn" setting is on, force the window on top of all other
; windows, and don't let it be minimized or closed.
if (Stubborn)
Gui, +AlwaysOnTop -SysMenu -Resize
Gui, Color, %Window_colour% ; Set window colour
Gui, font, s%Text_size% c%Text_colour% ; Set text font size and colour
Gui, %PopWindowName%:Add, Text, , %Window_text% ; Add text to window
; Show the window at the top left of the monitor
Gui, %PopWindowName%:Show, X%monitor_Left% Y%monitor_Top%
Gui, %PopWindowName%:Maximize ; Maximize the window
}

; Wait the specified time. If "Stubborn" is set, each second, we move each
; window back to the top left of its monitor, and re-maximize it.
Loop, %Duration_in_s% ; Loop over the # seconds we're pausing
{
if (Stubborn)
{
Loop, %monitor_count% ; Loop over the monitors
{
SysGet, monitor_, Monitor, %A_Index% ; Get the coords of a monitor
ID := "ahk_id " . WinIDs%A_Index% ; Get the window's ID from array
; Move the window back to the top left of the monitor
WinMove, %ID%, , %monitor_Left%, %monitor_Top%
WinMaximize, %ID% ; Maximize the window again
}
}
Sleep, 1000 ; Wait 1000 ms, i.e. 1 second
}

ExitApp ; Exit, closing all of the windows we created


June 2017

S M T W T F S
    123
45678910
11121314151617
18192021222324
252627282930 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 22nd, 2017 08:32 pm
Powered by Dreamwidth Studios