11

I want to write a python script on Windows that saves the title of the program that the user uses at a given time like the http://www.rescuetime.com . I don't want to use rescuetime because of privacy consideration but instead write a script that does something similar myself to capture data about how much I use my computer.

Is there some easy command that I can use to read that information?

Christian
  • 23,801
  • 35
  • 124
  • 210

2 Answers2

20

From daniweb

  import win32gui
  w=win32gui
  w.GetWindowText (w.GetForegroundWindow())
Ólafur Waage
  • 66,813
  • 19
  • 139
  • 194
1

It might already be too late, but here's what should work on most operating systems:

import pyautogui
window_title = pyautogui.getActiveWindowTitle()

(I'm not sure if it works for Ubuntu, but Mac Os, Linux and Windows are normally supported)

Jeremy Caney
  • 6,191
  • 35
  • 44
  • 70
Daveloper
  • 11
  • 1
  • pyautogui seems to have quite some issues when trying to install. I'm on mac os and the pyobjc-core package failed to install no matter what I tried. –  Mar 06 '22 at 21:08
  • `import pygetwindow` instead. I guess the feature is not ready to merge into `pyautogui` – Tuan Chau Apr 05 '22 at 01:47