List of all open windows for all apps

I am writing a Time Billing system and want to allow the user to track what documents (ie window names) they have open in given applications (eg Photoshop), and for how long, so they can be charged to a client. I mainly need this for macOS and Windows, but potentially Linux too. Is there an easy way to do this?

I can get a list of the current processes using:

Dim tempProcessMBS As New ProcessMBS 'for macOS and Windows

or

result = shell("tasklist") 'for Windows

or

result = shell("ps aux") 'for macOS and Linux

But how do I get a list of the documents (or window titles) they have open at any given time? If I knew the documents, I could use the lsof command, but I don’t.

For macOS I have tried CGSWindowMBS, but it doesn’t return the window title names.
For Windows, I intend to try WindowsListMBS. I can get the windows in the frontmost application using https://www.monkeybreadsoftware.net/accessibility-accessibilitymbs-method9.shtml#25, but not the others.
For Linux, I shall try LinuxProcessMBS.OpenFiles

Is this the right direction? Has anyone already accomplished this?

@David Cox — Ouch! AFAIK it will be very difficult to achieve that!

On macOS, you may have access to the windows opened by an application but only if the user has already activated accessibility features.

But overall, your idea goes against what every OS tries to achieve, i.e. increase security by isolating processes. So I would say you are not going to the right direction. Also problems about privacy must be taken into account.

So why would you want to achieve a kind of “automatic client detection” where it seems much easier to ask the user about it?

I am modernising another Xojo user’s app and it has this feature, but the app is macOS only. I plan to show the user a list of the running applications and get them to choose just the ones they want to track, plus only the file extensions they want, then use something like LSOF to get the list of open files and filter it according to their settings.

In the current app you can run it in detection mode in the background all day. At the end of the day you can pick the lists of items to add to your Daily Log and apply them to a particular client, with all the start and end times auto-entered. Sounds like a good feature to me!

@David Cox — The problem here is that there is no way to determine for how long a file has been used:

  1. An application can open a file, read it all and close it. Then it appears that this app is not even using that file.
  2. Even if an application keeps a file open, you cannot be sure it is actually used by the user! Maybe it just lays in a hidden window or something.

Your macOS-only app can use FSEvents, which is a very powerful way of observing files even between app-launches and system restarts, but I am still not sure it can help you determining the duration a file was actually used.

IMHO whatever the current app is claiming to do or measure, I think its developer was a bit mistaken!

Please try our MBS classes.

We used to get front window name for a tool used by a client.

I saw a repair guy earlier today, then he goes away to another client and sometimes later I noticed he forgots his work sheet.

That piece of paper holds clients details: name, reasonof the visit, time in and out, etc.

doing that in a software is a good idea, easy to do.

What you ask is very difficult - IMHO - to do automatically, as already written: what if the user have many different documents open but do nothing with it for a “certain” time: (s)he is smoking a cigarette, drinking tea, coffe, orange juice, eating, whatever…

At last, as with all humain doings, asking the user to write (like in the paper above) the start / end dates, you will fall into the “Doh ! I forget to write the start / end hours”.

On an iPhone * application, you may (if possible) add a 15 minutes reminder (user selected interval) that will ring the iPhone that amount of time after the last “End time”…

  • or Android, when available.

Did I told you that I loved the idea ?

I used to work for a law firm, where they kept timesheets to charge clients, and they told the story of a lawyer who died and went to hell. While processing the devil says that he expected the lawyer to arrive many years earlier, but the lawyer says he is only 40. The devil exclaims that according to the lawyer’s timesheets, the lawyer is over 200!

I am aware of the problems. I have built in a stopwatch and launch files button so the synchronisation can ideally be accurate. When they save that daily log record, the stopwatch is stopped and the hours added. If they accidentally leave the record open and stopwatch running and go to lunch, upon returning they can reset the lunch hours and restart the stopwatch from the pre-lunch time. This is the normal process, but…

Why not allow the augmentation of this process with an automated one for people who would like the computer to do the stopwatch functions for them, albeit potentially inaccurate. What if I forget to start the stopwatch, or can’t remember when I started editing a client’s document, the ‘window-watching’ log will allow them to see the actual launch and quit times, then decide if they want to add these as daily log items.

Use System Events with AppleScript. See for instance https://stackoverflow.com/questions/33420848/applescript-get-title-of-a-window .