Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It is possible to track what apps are in use and what file is opened with nodejs

For a future project, I need to track user activity to record their productivity time. I want to detect which file is currently open in apps like Adobe Photoshop for example and detect when the user switches to other app or another file/tab.

To make my desktop app, I wish to use electron JS

Can you just give me some tracks to follow ?I don't find any nodejs library that allow me to do that, but I know that is possible because it already done with electron apps like:

  • Chronos https://electronjs.org/apps/chronos-timetracker
  • Paymo https://electronjs.org/apps/paymo-time-tracker
  • ScreenAware https://electronjs.org/apps/screenaware

And an other App which not seems to be built with electron : https://desktime.com/features

Thanks for your help

like image 316
Arthur Eudeline Avatar asked Oct 14 '25 05:10

Arthur Eudeline


1 Answers

node.js doesn't have the capabilities you require, however it can call external programs to get the job done. The way I see it, you would need to have a PowerShell script (or C# program) to get the active window from the operating system, and find all open file handles for the process behind that window. You would invoke this script from node, and build your gui around it.

A good starting point is this module active-window which works exacty as I described: a nodejs process calls some external scripts (in bash/PowerShell) that use OS specific primitives to get the active window.

To get the list of files opened by a process, you could use the handle utility from Sysinternals. However you may run into a small problem: apps like Photoshop usually don't keep the file handle open, they just open it when saving the file. This means that you won't always be able to detect open files. I guess trial and error is your friend here.

To find open tabs, it's more complicated. Tabs usually indicate the internal state of an app, and this information is held in memory. Some apps might offer an API, but that's not guaranteed. I guess screenshots are the way to go here.

like image 109
mihai Avatar answered Oct 16 '25 21:10

mihai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!