For example, I normally open mousepad (xfce equivalent of gedit) from the applications menu. However, I know that you can also do this in a terminal by typing mousepad
.
Following this example, what I want is whenever I open mousepad via GUI, a new line is written in a log file stating something like Sep 5 15:35:11 lucho@lucho:~$ mousepad
. More in general, what I want is to log all GUI activities that are potentially do-able via command-line (like opening programs, changing permissions, modifying a system settings, etc) but written in its alternative command-line execution format. I want this in order to improve my knowledge of how to use the command-line (without going through the man
pages). There are many things I do through the GUI which I don't do via command-line (some potentially automatable via a script or via keyboard shortcuts) and having this log file would be a good way to learn them.
I'm aware of the existence of the syslog file in /var/log
but that is not what I need. The Activity Log Manager app from Ubuntu repositories does not show command-line format, so far as I know. I need something like the .bash_history file that exist in my home folder but recording my GUI-based activities.
Best Answer
Introduction
While it's not possible to log all GUI actions, such things as logging commands that correspond to open windows can be done. Below is the simple python script that does the job. It's still in development, but does 90% of the required task.
Source code
Test run:
The script shows timestamp, event type, the window PID, and the corresponding command.
How to use
The standard rules of any script apply. Make sure you store the script in
~/bin
directory. If you don't have~/bin
directory , then create one. Save script file there and ensure it is executable withchmod +x ~/bin/log_open_windows.py
. After than you can run it from command line at any time you wish by calling~/log_open_windows.py
in command-line.