是否可以使用python脚本运行当前应用程序

时间:2021-01-12 23:44:05

I am very much concerned about my productivity all the time. I have recently come across this beautiful chrome extension Limitless

我一直非常关心自己的工作效率。我最近遇到了这个美丽的镀铬扩展无限

But this is only measuring what i'm doing within the chrome application. As I work most of the time with pdfs, videos etc, I want to develop similar application for linux(ubuntu) desktop enviroment.

但这仅仅是衡量我在chrome应用程序中所做的事情。由于我大部分时间都在使用pdf,视频等工作,所以我想为linux(ubuntu)桌面环境开发类似的应用程序。

Basically I want the script to run continuously as long as the workstation is on. It should be able to know what I'm currently looking at (for eg a pdf file or a lecture video in vlc) and get the name of the respective file, start time, end times etc and finally post to db. It is better if it could know if the system is idle or at sleep.

基本上,只要工作站打开,我希望脚本能够连续运行。它应该能够知道我正在查看的内容(例如,vlc中的pdf文件或讲座视频)并获取相应文件的名称,开始时间,结束时间等,最后发布到db。如果它能够知道系统是空闲还是处于睡眠状态会更好。

I don't have slightest clue at bash scripting. so my questions is could this task be accomplished with python.

我对bash脚本没有丝毫的线索。所以我的问题是可以用python完成这项任务。

What I've tried?
I started with a search in google "get current application python", "current window title python" etc etc and really surprised to see absurd results.

我试过了什么?我开始搜索谷歌“获取当前应用程序python”,“当前窗口标题python”等等,真的很惊讶看到荒谬的结果。

Please give me pointers on this.

请指点我。

2 个解决方案

#1


1  

I think you are asking for vocabulary. So I give you what I know.

我想你要求词汇量。所以我告诉你我所知道的。

You are using Ubuntu so your Window Manager may be Gnome. The window manager knows which window has the focus. So maybe you want to find out which window has the focus and you want to map it to the Process that opened the window. What you need to focus on is is module for Python or a Python Binding for the window manager. This module is likely to also be able to control the windows.

您正在使用Ubuntu,因此您的Window Manager可能是Gnome。窗口管理器知道哪个窗口具有焦点。因此,您可能希望找出哪个窗口具有焦点,并且您希望将其映射到打开窗口的Process。您需要关注的是Python的模块或窗口管理器的Python绑定。该模块很可能也能够控制窗口。

The window manager is started with startx.

窗口管理器以startx启动。

#2


0  

You could try to call a command line tool and catch the results

您可以尝试调用命令行工具并捕获结果

How do get the process list on command line: https://*.com/questions/53489/how-do-you-list-all-processes-on-the-command-line-in-windows

如何在命令行上获取进程列表:https://*.com/questions/53489/how-do-you-list-all-processes-on-the-command-line-in-windows

And how to call a tool with python: Python subprocess.call and subprocess.Popen stdout

以及如何使用python调用工具:Python subprocess.call和subprocess.Popen stdout

[edit] Repeating the call in Intervals and counting the intervals a process were running gives you a good estimation of running time of a process...

[编辑]在Intervals中重复调用并计算进程运行的时间间隔,可以很好地估计进程的运行时间......

[edit2] As GreenAsJade said, you search a way to find out which windows has the focus. See How do I detect the currently focused application?

[edit2]正如GreenAsJade所说,你搜索一种方法来找出哪些窗口具有焦点。请参阅如何检测当前关注的应用程序?

#1


1  

I think you are asking for vocabulary. So I give you what I know.

我想你要求词汇量。所以我告诉你我所知道的。

You are using Ubuntu so your Window Manager may be Gnome. The window manager knows which window has the focus. So maybe you want to find out which window has the focus and you want to map it to the Process that opened the window. What you need to focus on is is module for Python or a Python Binding for the window manager. This module is likely to also be able to control the windows.

您正在使用Ubuntu,因此您的Window Manager可能是Gnome。窗口管理器知道哪个窗口具有焦点。因此,您可能希望找出哪个窗口具有焦点,并且您希望将其映射到打开窗口的Process。您需要关注的是Python的模块或窗口管理器的Python绑定。该模块很可能也能够控制窗口。

The window manager is started with startx.

窗口管理器以startx启动。

#2


0  

You could try to call a command line tool and catch the results

您可以尝试调用命令行工具并捕获结果

How do get the process list on command line: https://*.com/questions/53489/how-do-you-list-all-processes-on-the-command-line-in-windows

如何在命令行上获取进程列表:https://*.com/questions/53489/how-do-you-list-all-processes-on-the-command-line-in-windows

And how to call a tool with python: Python subprocess.call and subprocess.Popen stdout

以及如何使用python调用工具:Python subprocess.call和subprocess.Popen stdout

[edit] Repeating the call in Intervals and counting the intervals a process were running gives you a good estimation of running time of a process...

[编辑]在Intervals中重复调用并计算进程运行的时间间隔,可以很好地估计进程的运行时间......

[edit2] As GreenAsJade said, you search a way to find out which windows has the focus. See How do I detect the currently focused application?

[edit2]正如GreenAsJade所说,你搜索一种方法来找出哪些窗口具有焦点。请参阅如何检测当前关注的应用程序?