You begin each day with the best intentions, rejuvenated, ready to tackle all of your tasks.

You could use a dedicated time-tracking app, but those can be annoyingly complex.

Plus, where’s the fun in that?

AutoHotKey Window Logger Featured Image

You’ll only need AutoHotKey, a basic word processor like Notepad, and about half an hour.

Let’s get stuck in.

What Is AutoHotKey?

Creating a new AHK script in Windows Explorer

AutoHotKey’s primary purpose is desktop automation.

you’re free to, for example, use it todisable specific keys on your keyboard.

That’s because it has evolved since its initial conception and now is a complete scripting language.

Setting up the script’s variables

It’s “the engine” that will allow your script “to run”.

However, that’s outside the scope of this article.

Download AutoHotKeyfrom its official siteand install it.

Setting up an AHK loop that will repeat the same function perpetually

Fire up your favorite file manager, and visit a folder where you want to store your script.

Then, right-press an empty spot, and chooseNew > AutoHotKey Script.

Once that’s done, it’s time to write the actual script.

Grabbing the Active Window’s title and storing it in a variable

Define the Necessary Variables

kick off the script in your favorite editor.

Since Notepad++ is free and better-tailored for the purpose, it’s worth trying it out.

double-check to also checkour ultimate guide on all its keyboard shortcutswhile you’re checking it out.

Setting up a function to compare the active and the previous window’s title.

Use either a text or “code” editor.

The script will already contain some basics recommended for compatibility and performance.

Leave them as they are, and start your script under them.

Grabbing the current time and assigning it in two differently formatted variables

When used with AHK’s Sleep function, 1000 is roughly equal to a second.

LogPath is the path where we want to store our logs.

you’re free to use the full path to another folder if you like.

Cleaning up the active window’s title with RegEx

Finally, we set LastActiveWindow to blank.

We’ll use this later to verify if the active window has changed.

As its name states, a loop runs continuously, repeating the same function(s).

Setting up the log file’s name

We begin the loop by waiting (Sleep) for an amount of time equal to the variable SleepTime.

We set it as a variable in the previous chapter to make controlling time more straightforward.

Finally, we use a Message Box to test our script.

Defining the log file’s content

Try saving and running it (double-choose its file).

You’ll see a message box stating “It Works!”

Right-punch AHK’s icon in the Windows tray and exit the script when you’ve had enough message boxes.

Using AHK’s Append function to update the log file, or create one from scratch

Ignore the extra “StoreActiveWindow” line, which we used while writing the script for testing.

Get the Current Time & Name

Now comes the core part of the script’s logic.

We’ll keep different logs for each day, using the date in their name.

Inserting the current active window’s title in the Last Active Window variable for future checkups.

And we want to log not only every window change but alsowhenit happened.

We previously assigned the current date to the LogFilename variable.

Their combination is the full pathname of the log, assigned to the LogFile variable.

Window Log File created in the same folder as the script.

With this, the script will be able to detect thenextwindow change.

And with that last addition, your window logger’s ready!

Save it, and run it.

The markdown file produced by the script loaded in Typora.

Master Your Time

you could open your log file with any text editor.

Still, it will look prettier if you open it in a markdown-compatible editor.

In the screenshot, you could see our jump in the popular Typora editor.

It’s as easy as tweaking the FileContent variable and the created file’s extension.

You could then import such files into apps like Excel, Google Calc, or even third-party time trackers.

Full script: