Например, Windows запускает новый процесс выбранного приложения и передает имя открываемого файла процессу с дополнительным аргументом командной строки (для моего приложения: argv [0] - исполняемый файл, argv [1] - открываемый файл). Ubuntu запускает мое приложение, но процесс не получает никаких дополнительных аргументов (только argv [0]). Как мое приложение может узнать имя файла, который открывает пользователь?
The file manager will pass along the URI of the file that you right-clicked in order to select "Open With".
In linux desktops, applications are launched using a launcher file. A launcher file is a plain text file with the .desktop
extension. It contains information for the desktop environment on how to start the application, what icon to use, how and where to display it in the menu, etc. The Open With Other Application" list in Files (nautilus) is populated by the
.desktop` files present on your system.
It is in the .desktop
file on the Exec=
line that arguments are defined. For example, for the editor Gedit, this line is
Exec=gedit %U
Only when the Exec=
entry of the .desktop
file contains an argument, the system will pass the argument it received from Files (nautilus) to the program.