Polkit rule question
Hey Guys!
I have a little Problem with Polkit. I installed a gnome extension called "Custom Command Toggle" that adds a custom toggle to the quick menu that can run a command when toggled. I wrote 2 scripts, one for on-toggle, one for off-toggle. They both just use sudo systemctl start and stop to basically switch between 2 sets of services depending on the toggle. This obviously requires sudo rights. I don't want to have to input my password whenever I toggle the button because it will happen pretty often.
So I want to create a polkit rule to allow the execution of these scripts without a password prompt. I created a rules file in etc/polkit-1/rules.d and copied the contents of another extension that had installed the rule there. The rules file looks like this:
polkit.addRule(function(action, subject) {
if (action.id === "org.freedesktop.policykit.exec" &&
action.lookup( 'program' ).endsWith( '/SyncToggleOn' )
{
return polkit.Result.YES;
}
else if (action.id === "org.freedesktop.policykit.exec" &&
action.lookup( 'program' ).endsWith( '/SyncToggleOff' ))
{
return polkit.Result.YES;
}
});
I have also tried to use just the === operator instead of endswith and then the full file path of the script, but it didn't work so I attempted this. The extension still asks for a password. Since I have no experience with polkit at all, I don't know what to do to get this to work.
If what I want to do is not possible, could I get the desired result by adding the commands for systemctl start and stop to the no password list for sudo? Any help is appreciated.
Posted Jun 2, 2026, 6:47 AM UTC