gapplication command examples

gapplication command examples

gapplication – D-Bus application launcher

From the commandline Launching an application:

gapplication launch org.example.fooview


Opening a file with an application:

gapplication launch org.example.fooview ~/


Opening many files with an application:

gapplication launch org.example.fooview ~/foos/*.foo


Invoking an action on an application:

gapplication action org.example.fooview create


Invoking an action on an application, with an action:

gapplication action org.example.fooview show-item '"item_id_828739"'


From the Exec lines of a .desktop file

The commandline interface of gapplication was designed so that it could be used directly from the Exec line of a  .desktop file.

You might want to do this to allow for backwards compatibility with implementations of the specification that do not understand how to do D-Bus activation, without having to install a separate utility program.

Consider the following example:

[Desktop Entry]
Name=Foo Viewer
Exec=gapplication launch org.example.fooview %F
[Desktop Action gallery]
Name=Browse Gallery
Exec=gapplication action org.example.fooview gallery
[Desktop Action create]
Name=Create a new Foo!
Exec=gapplication action org.example.fooview create


From a script

If installing an application that supports D-Bus activation you may still want to put a file in /usr/bin so that your program can be started from a terminal.

It is possible for this file to be a shell script. The script can handle arguments such as –help and –version directly. It can also parse other command line arguments and convert them to uses of gapplication to activate the application, open files, or invoke actions.

Here is a simplified example, as may be installed in /usr/bin/fooview:

case "$1" in
echo "see 'man fooview' for more information"
echo "fooview 1.2"
gapplication action org.example.fooview gallery
gapplication action org.example.fooview create
echo "unrecognised commandline argument"
exit 1
gapplication launch org.example.fooview "$@"


Leave a Reply

Your email address will not be published. Required fields are marked *