Can an application query about its snap context?

This is for a python based command line app that is built using pyinstalled and then packaged as a strict snap.

What is a safe and reasonable way for the app to query about its snap context, for example, does it run under snap? (we use also other packagers), is the raw-usb interface connected? and so on.

Try checking if the $SNAP environment variable is set… That’s usually a safe bet…

Thanks @ogra, what about checking if a certain interface is connected?

I am trying to avoid launching a snap command subprocess and scraping its text.

Ok, I found this one Snapctl is-connected plug|slot

‘snapctl’ need to be run from the snap and it can return the interface status as the subprocess exit code.

1 Like