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/ 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 file:///$SNAP_USER_DATA should open a file manager pointing to the application specific home dir


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.