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
Run this commands:
echo 'alias obs="primusrun obs"' >> ~/.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:
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
optirun before the command.
Comment=Free and Open Source Streaming/Recording Software
Comment[ru]=Бесплатная программа с открытым кодом для записи/трансляции видео
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 primusrun obs, but this won't cause any issue.