I know this question is old, but I'd like to give my own contribution as well.
This is valid for any distribution, not only Ubuntu.
1. Create a command alias
So then you will be able to run the application from terminal or everywhere else that references it. This is the most generalized possible solution for the problem. For my example, I'll be editing the command obs
to always run with primusrun
.
Run this commands:
echo 'alias obs="primusrun obs"' >> ~/.bashrc
source ~/.bashrc
Now when you run obs
in the terminal, it will call primusrun obs
instead.
If then you want to run the application without primusrun
for whatever reason, you'll need to make an absolute call to its executable. That's easy:
$ /usr/bin/obs
This will work as well for the desktop launcher if it calls for the relative command obs
too, but if the launcher calls for the absolute path, like /usr/bin/obs
, then you'll need to go to step 2 as well.
2. Edit the launcher
Find where the .desktop
file is located.
If it is a userspace application (like Wine applications), it should be under ~/.local/share/applications
, otherwise it should be under /usr/share/applications
. Find the .desktop
file for your application (this can be somewhat tricky, as some file managers will display the application title instead of the actual file name) and edit it with you favorite text editor:
sudo nano /usr/share/applications/obs.desktop
Find the line Exec=
and add primusrun
or optirun
before the command.
[Desktop Entry]
Version=1.0
Name=OBS
GenericName=Streaming/Recording Software
Comment=Free and Open Source Streaming/Recording Software
Comment[ru]=Бесплатная программа с открытым кодом для записи/трансляции видео
Exec=primusrun /usr/bin/obs
Icon=obs
Terminal=false
Type=Application
Categories=AudioVideo;Recorder;
StartupNotify=true
Save and quit.
Bear in mind that if the launcher calls for the relative command (just obs
instead of /usr/bin/obs
) this will effectivelly cause the desktop launcher to run the command with two primusrun
like primusrun primusrun obs
, but this won't cause any issue.