How to run the host system commands in a snap?

In my snap app aphoto, I ran a shell script and output like this:
/snap/aphoto/x1/snap/run_snap.sh: line 28: nautilus: command not found

And I am sure the command tools “nautilus” does exist in the host system Ubuntu.

How can I do?

Thanks in advance.

unles there is an interface for something, snap packages can not simply call commands from the host for security reasons … what desktop snaps can do is to use xdg-open … something like:

#! /bin/sh

xdg-open "$@"

and then calling this script like run_script.sh file:///$SNAP_USER_DATA should open a file manager pointing to the application specific home dir

4 Likes

Thanks very much for your reply.
The problem is that the snap can not run host system’s commands in the snap scripts.

xdg-open and nautilus are all in host system PATH /usr/bin.

It seems like host system PATH /usr/bin is invisible in snaps.
So the scripts in snap echo command not found.

there is an xdg-open in the snap environments PATH, do not use /usr/bin when you execute xdg-open, literally copy/paste my script snippet … (and make sure the desktop plug is defined (and connected) for your app)

1 Like

The xdg-open command can open a file with the host’s default application associate to the file’s type, it can not directly launch a specific application.

You can launch a file manager application(not necessarily Nautilus) by giving a directory path as an argument to xdg-open.

Yes, you’re right. I have had a try. It can work well in a snap. Thanks a lot.:grinning:

Got it.
Thanks very much.

Probably a dumb question but, if the host system is generally unavailable to a snap packages, how does this manage to function? https://github.com/adnanh/webhook

seems it doesn’t …

the packager would have to make it a classic snap to make it work, but seems they did not bother to request permissions for classic confinement … sadly they also did not unlist/delete the snap from the store though, which leaves it there in a broken state for users to install …

1 Like