Last Updated: February 25, 2016
·
3.353K
· michelgotta

Use Sublime Text 3 as your project time tracker

I work for a small web agency and tracking the time you work on projects is always a pain. Specially when you switch between different projects a lot you can not precisely say how much time you spend on some project at the end of the day.

Sublime Text 3 comes with some easy tools to extend to perfect your workflows and write simple plugins in Python such as the Event Listener.

In this example I used the on_post_save event to check in which project I work and just tracks the current timestamp and saves it to hidden file named .timetracker. The file structure in this example is ~/dev/projects/name-of-your-project/:

import sublime, sublime_plugin

import time

class TimetrackerCommand(sublime_plugin.EventListener):
    def on_post_save(self, view):
        string = open('~/.timetracker', 'r').read()
        # Get the filename of your saved file
        saved_file = view.file_name()

        # Check if your in any of your development projects   
        if 'dev/projects' in saved_file:
            project = saved_file.split('projects/')[1].split('/')[0]
            output = project + ":" + str(time.time()) + "\n"
            string = string + output;

            f = open('~/.timetracker', 'w')
            f.write(string)
            f.close()

            pass

The data is stored in a simple your-current-project:1385633522.528532 in each line. I used PHP to read out the data and visualize it with a bar graph but you could use the data in any other language or visualization format from Excel to connecting it via an API to your prefered time tracking tool.

Of course, there are nicer ways to save structured data, this is just a stripped to the bone example. Use this code snippet as inspiration, change it to your development directory structure and maybe integrate it to your daily workflow.

Note: There is already a Sublime Plugin for WakaTime

1 Response
Add your response

The link to WakaTime is old and has moved to https://wakatime.com

over 1 year ago ·