I found this KDE Open recently closed application question and it's exactly what I'd like to do, however I am on ubuntu. The only answer on that question is the 'recently used' part of the launcher, but the recently used list doesn't include apps locked to the launcher.
Normally I run most things through the terminal, but things like browsers, I'll run from the launcher. Sometimes I accidentally close them.
In short: I'd like the 'ctrl-shift-t' functionality that most browsers have for tabs applied to programs in ubuntu.
If that came in the form of a script, that's fine; I don't really have much experience writing bash scripts, so an explanation or links to docs are appreciated.
Is there a list of recently closed programs stored somewhere on the disk? I know it would probably be the logs, but that would be a hassle to figure out how to parse, I think? I guess I'm hoping there's a nice little log file somewhere that keeps a record of apps closed/opened and the path to the program that runs/starts them. Also: if I wanted ubuntu to create a log file like that, how would I do that?
71 Answer
As requested in comments, a conceptual answer, no ready-to-use script.
Explanation on concept; how to log the most recently closed application
Introduction
From a list of processes & pids, it is hard to decide which belongs to an application or another process. Since you mention GUI applications however, we can log windows, which gives us all information we need to decide which was the most recently closed application.
Using wmctrl to list running GUI applications
wmctrl (not on your system by default) is a command- line tool that can give you information on currently existing windows. The command:
wmctrl -lpproduces a window list, looking like:
---
0x02c0000c 0 23772 jacob-System-Product-Name Hud
0x02e0000a -1 23877 jacob-System-Product-Name Desktop
0x0480001d 0 28367 jacob-System-Product-Name Ask Ubuntu General Room | chat.stackexchange.com - Mozilla Firefox
0x05200007 0 26724 jacob-System-Product-Name System Monitor
0x05800084 0 27183 jacob-System-Product-Name *Untitled Document 1 - gedit
---In the second column of the list, you can see the pids of the currently opened windows, like: 23877, 28367
From these pids, we can retrieve the process (application) that owns the window, using the command:
ps -o cmd= <pid>e.g.:
$ ps -o cmd= 27183
geditThen all we need to do is run a loop with a period of a few seconds, comparing the (unique) list of processes, owning a window (=applications), with the list of a few seconds ago. If a process "left" the list, that's the most recently closed window. In short:
(Conceptual) overview of the loop (python style)
applications1 = get_applications()
while True: time.sleep(3) applications2 = get_applications() closed = [app for app in applications1 if not app in applications2] if closed: most_recent = closed[0] # store the process in a file, to be available to run as most recently closed open(f, "wt").write(most_recent) application1 = application2where f is the path to a file where the most recent application is written to. Subsequently have another process/command start the application in the file and the setup is completed.
Language?
No doubt this can be done in pretty much all script languages. To me, python seems just the right one for easily producing scripts like this...
Note
Note that the schematic code above is just for example, no tested code!
4