A Simple Time Tracking Tool Using Batch Files and Windows Task Scheduler

Updated on March 5, 2017

Before We Begin

If you're a time conscious person like me, you have probably attempted to find out where your missing hours go. We often hit the "age of awakening", quarter-life crisis, or anything that strikes you and make you aware that you're not immortal and your time is running out. Before I begin, I have to set the line between being "conscious" and being "obsessed". The first one aims for self-improvement and the latter, I believe, is simply self-abuse. While being conscious about time keeps you productive, obsessing about it does the opposite. Having anxiety all my life, I am more than aware that stressing too much about something causes a person to procrastinate more.

Now that we have that cleared out..

Say hello to your nagging partner.
Say hello to your nagging partner.

Resources

Not as fancy as you thought? This is a simple tracker I made under 15 minutes and you can set it up in less than that amount of time. I'm a proud fan of resourcefulness and brief idea-into-code moments. I used tools that are pre-installed in every computer:

  • Windows Task Scheduler
  • Command Line
  • Notepad

If you're using a different operating system, you may use your OS's counterpart of these utilities.

Unlike your partners, these batch files don't ask for too much (disk space).
Unlike your partners, these batch files don't ask for too much (disk space).

Batch Files

I wrote three batch files that perform very specific tasks. These are all the files you need for the tracker. Each one contains a set of commands that are executed in the command line.

  • reasons.bat
    Collects the reasons you were away from your computer when you answer the question "Why were you away?"
  • timein.bat
    Logs the date and time that you logged in to your computer.
  • timeout.bat
    Logs the date and time that you logged off from your computer.

Simply open a notepad and paste the codes below and save them with a .bat file extension so you end up with three batch files.

Note: Different operating systems require different syntax. Despite having alternatives for the tools used, the codes below may only work for Windows and you will have to convert them for your operating system.

reasons.bat

echo off
set d=%date%
set t=%time%

setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (C:\Users\<username>\Documents\Track\Logs\time-out.log) do (
set lasttimeout=%%a
)

echo You've been away from %lasttimeout% to %d% %t%.
set /p exp="Why were you away? "
echo From %lasttimeout% to %d% %t% - %exp%. >> C:\Users\<username>\Documents\Track\Logs\reasons.log
pause

timein.bat

echo %date% %time% >> C:\Users\<username>\Documents\Track\Logs\time-in.log

timeout.log

echo %date% %time% >> C:\Users\<username>\Documents\Track\Logs\time-out.log

Log Files

In order to track your time, your logged in and away time must be stored somewhere. Here we will use a simple .log file extension. Replace the directories indicated in the code. Make sure that the directories exist and keep all the log files in one directory for better organization. The log files automatically be generated if they don't already exist and will be updated for every time in and time out.

For reasons.bat, replace the following lines:

  • C:\Users\<username>\Documents\Track\Logs\time-out.log
  • C:\Users\<username>\Documents\Track\Logs\reasons.log

For timein.bat, replace the line below:

  • C:\Users\<username>\Documents\Track\Logs\time-in.log

For timeout.bat, replace the line below:

  • C:\Users\<username>\Documents\Track\Logs\time-out.log

You can run the batch files to see if it works by double-clicking each one. The log files should be automatically generated if they don't already exist and updated if they already do.

Scheduling The Execution

Now that the code is working, we have to schedule its execution. Our goal is for the timeout.bat program to run every time the computer locks; and the timein.bat and reasons.bat programs to run every time we log into or unlock the computer.

Launch the Task Scheduler application by typing the program name into the Search programs and files field after clicking the Windows Start icon or navigating to
Start > All Programs > Accessories > System Tools and clicking "Task Scheduler".

Create a task by clicking "Create Task..." from the Actions pane.

Next would be a series of photos of the Task Scheduler settings. We'll be creating two tasks - Time In and Time Out.

Launching the Windows Task Scheduler.
Launching the Windows Task Scheduler.
Task Scheduler: Create Task
Task Scheduler: Create Task
Task Scheduler: General Tab
Task Scheduler: General Tab
Task Scheduler: Triggers (On workstation unlock)
Task Scheduler: Triggers (On workstation unlock)

Triggers

We set the value for "Begin the task" to "On workstation unlock" and the "Specific user" to our username. This means that the timein.bat program will execute when we unlock or log in to the computer using the specified username.

Task Scheduler: Actions (Time In)
Task Scheduler: Actions (Time In)
Task Scheduler: Actions (Reasons)
Task Scheduler: Actions (Reasons)

Actions

This is the part where we indicate the location of the batch files or programs we want to execute on the triggers we set previously. To create a new action, click the "New..." button. We will create two actions for this task. The first one will run the timein.bat file to log the time stamp when you log in. The second one will run the reasons.bat file to ask for the reason why you were away.

Replace the paths below with the path where you saved your batch files:

Time In
Program/script: "C:\Users\<username>\Documents\Track\Batch Files\timein.bat"
Start in (optional): C:\Users\<username>\Documents\Track\Batch Files\

Reasons
Program/script: "C:\Users\<username>\Documents\Track\Batch Files\reasons.bat"
Start in (optional): C:\Users\<username>\Documents\Track\Batch Files\

Note: Do not remove the double quotation marks for the Program/script value. You may encounter errors for paths that have space in it (e.g. "Batch Files").

Task Scheduler: Conditions
Task Scheduler: Conditions
Task Scheduler: Settings
Task Scheduler: Settings

Conditions and Settings

For the Conditions tab, I unchecked "Start the task only if the computer is on AC power" under the Power section since I'm using a laptop and my charger is not always plugged in especially during meetings. I did not make any changes for the Settings tab.

The next screenshots will show you the settings for the Time Out task. You'll have to create a new task just as before. Some of the settings are similar to what we did for the Time In task so you can assume that if the screenshot is not present below, you can apply the same settings in the screenshots for the Time In task.

Task Scheduler: General Tab
Task Scheduler: General Tab
Task Scheduler: Triggers (On workstation lock)
Task Scheduler: Triggers (On workstation lock)
Task Scheduler: Actions (Time Out)
Task Scheduler: Actions (Time Out)

After completing the steps above, you should have two new tasks in the Task Scheduler Library. One for Time In and another one for Time Out.

Task Scheduler Library
Task Scheduler Library

When we first created the batch files, we ran it manually (double-click) to see if it works. Now that we have created the tasks on Windows Task Scheduler, we will try running the tasks manually from the Task Scheduler to see if it works. This type of testing is very important if you want to save time tracing where the problem was.

Follow the step below to run the task from the Task Scheduler.

Task Scheduler: Run
Task Scheduler: Run
Prompt
Prompt

After entering the reason, you may check the log files generated in the directory you put into the batch files.

Typing a reason.
Typing a reason.
Logs.
Logs.

End of Tutorial

You can now try locking and unlocking your computer to see if it works. In order to make this tool useful, you must get into the habit of locking your computer whenever you are away. It's good security practice after all so you're hitting two birds with one stone. You can also use the data you collected to assess your habits and change them for the better. This tool helped me a lot when submitting weekly task reports for weeks where there were too many meetings that did not require me to bring my laptop. I have not had the time to improve this tool. For now, it works just fine.

As you can see, I've been using this for quite some time now so I already have a few records. Disregard some of the weird data since I demonstrated this to a colleague before writing an article about it. He's been using it for a while now and he said he can't believe how much time his coffee breaks take. Sometimes, lunch lasts for more than an hour and before you know it, the day is about to end and you didn't get anything done. This tool helped us be more productive and check areas where we can improve.

But like I said before, don't restrict yourself too much. It's important to take regular breaks since working for a few straight hours can make you less productive and prone to making errors. Make changes where you can so you can increase your productivity without burning out.

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, turbofuture.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://turbofuture.com/privacy-policy#gdpr

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)