summaryrefslogtreecommitdiff
path: root/docs/reference/gio/gapplication.xml
blob: 13e3f230071ad6b860d054696792a1a5c10d2404 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<refentry id="gapplication-tool" lang="en">
  <refentryinfo>
    <title>gapplication</title>
    <productname>GIO</productname>
    <authorgroup>
      <author>
        <contrib>Developer</contrib>
        <firstname>Ryan</firstname>
        <surname>Lortie</surname>
      </author>
    </authorgroup>
  </refentryinfo>

  <refmeta>
    <refentrytitle>gapplication</refentrytitle>
    <manvolnum>1</manvolnum>
    <refmiscinfo class="manual">User Commands</refmiscinfo>
  </refmeta>

  <refnamediv>
    <refname>gapplication</refname>
    <refpurpose>D-Bus application launcher</refpurpose>
  </refnamediv>

  <refsynopsisdiv>
    <cmdsynopsis>
      <command>gapplication</command>
      <arg choice="plain">help</arg>
      <arg choice="opt"><replaceable>COMMAND</replaceable></arg>
    </cmdsynopsis>
    <cmdsynopsis>
      <command>gapplication</command>
      <arg choice="plain">version</arg>
    </cmdsynopsis>
    <cmdsynopsis>
      <command>gapplication</command>
      <arg choice="plain">list-apps</arg>
    </cmdsynopsis>
    <cmdsynopsis>
      <command>gapplication</command>
      <arg choice="plain">launch</arg>
      <arg choice="plain"><replaceable>APPID</replaceable></arg>
    </cmdsynopsis>
    <cmdsynopsis>
      <command>gapplication</command>
      <arg choice="plain">launch</arg>
      <arg choice="plain"><replaceable>APPID</replaceable></arg>
      <arg choice="opt" rep="repeat"><replaceable>FILE</replaceable></arg>
    </cmdsynopsis>
    <cmdsynopsis>
      <command>gapplication</command>
      <arg choice="plain">list-actions</arg>
      <arg choice="plain"><replaceable>APPID</replaceable></arg>
    </cmdsynopsis>
    <cmdsynopsis>
      <command>gapplication</command>
      <arg choice="plain">action</arg>
      <arg choice="plain"><replaceable>APPID</replaceable></arg>
      <arg choice="plain"><replaceable>ACTION</replaceable></arg>
      <arg choice="opt"><replaceable>PARAMETER</replaceable></arg>
    </cmdsynopsis>
  </refsynopsisdiv>

  <refsect1>
    <title>Description</title>

    <para>
      <command>gapplication</command> is a commandline implementation of the client-side of the
      <interfacename>org.freedesktop.Application</interfacename> interface as specified by the freedesktop.org
      Desktop Entry Specification.
    </para>

    <para>
      <command>gapplication</command> can be used to start applications that have
      <varname>DBusActivatable</varname> set to <literal>true</literal> in their <filename>.desktop</filename>
      files and can be used to send messages to already-running instances of other applications.
    </para>

    <para>
      It is possible for applications to refer to <command>gapplication</command> in the <varname>Exec</varname>
      line of their <filename class='extension'>.desktop</filename> file to maintain backwards compatibility
      with implementations that do not directly support <varname>DBusActivatable</varname>.
    </para>

    <para>
      <command>gapplication</command> ships as part of <application>GLib</application>.
    </para>
  </refsect1>

  <refsect1>
    <title>Commands</title>

    <refsect2>
      <title>Global commands</title>

      <variablelist>
        <varlistentry>
          <term>
            <command>help</command>
            <arg choice="opt"><replaceable>COMMAND</replaceable></arg>
          </term>
          <listitem>
            <para>
              Displays a short synopsis of the available commands or provides detailed help on a specific
              command.
            </para>
          </listitem>
        </varlistentry>

        <varlistentry>
          <term>
            <command>version</command>
          </term>
          <listitem>
            <para>
              Prints the GLib version whence <command>gapplication</command> came.
            </para>
          </listitem>
        </varlistentry>

        <varlistentry>
          <term>
            <command>list-apps</command>
          </term>
          <listitem>
            <para>
              Prints a list of all application IDs that are known to support D-Bus activation.  This list is
              generated by scanning <filename class='extension'>.desktop</filename> files as per the current
              <envar>XDG_DATA_DIRS</envar>.
            </para>
          </listitem>
        </varlistentry>

        <varlistentry>
          <term>
            <command>launch</command>
            <arg choice="plain"><replaceable>APPID</replaceable></arg>
            <arg choice="opt" rep="repeat"><replaceable>FILE</replaceable></arg>
          </term>
          <listitem>
            <para>
              Launches an application.
            </para>
            <para> 
              The first parameter is the application ID in the familiar "reverse DNS" style (eg:
              '<literal>org.gnome.app</literal>') without the <filename class='extension'>.desktop</filename>
              suffix.
            </para>
            <para>
              Optionally, if additional parameters are given, they are treated as the names of files to open and
              may be filenames or URIs.  If no files are given then the application is simply activated.
            </para>
          </listitem>
        </varlistentry>

        <varlistentry>
          <term>
            <command>list-actions</command>
            <arg choice="plain"><replaceable>APPID</replaceable></arg>
          </term>
          <listitem>
            <para>
              List the actions declared in the application's <filename class='extension'>.desktop</filename>
              file.  The parameter is the application ID, as above.
            </para>
          </listitem>
        </varlistentry>

        <varlistentry>
          <term>
            <command>action</command>
            <arg choice="plain"><replaceable>APPID</replaceable></arg>
            <arg choice="plain"><replaceable>ACTION</replaceable></arg>
            <arg choice="opt"><replaceable>PARAMETER</replaceable></arg>
          </term>
          <listitem>
            <para>
              Invokes the named action (in the same way as would occur when activating an action specified in
              the <filename class='extension'>.desktop</filename> file).
            </para>
            <para>
              The application ID (as above) is the first parameter.  The action name follows.
            </para>
            <para>
              Optionally, following the action name can be one parameter, in GVariant format, given as a single
              argument.  Make sure to use sufficient quoting.
            </para>
          </listitem>
        </varlistentry>

      </variablelist>
    </refsect2>
  </refsect1>

  <refsect1>
    <title>Examples</title>

    <refsect2>
      <title>From the commandline</title>

      <para>
        Launching an application:
      </para>

      <programlisting>
        gapplication launch org.example.fooview
      </programlisting>

      <para>
        Opening a file with an application:
      </para>

      <programlisting>
        gapplication launch org.example.fooview ~/file.foo
      </programlisting>

      <para>
        Opening many files with an application:
      </para>

      <programlisting>
        gapplication launch org.example.fooview ~/foos/*.foo
      </programlisting>

      <para>
        Invoking an action on an application:
      </para>

      <programlisting>
        gapplication action org.example.fooview create
      </programlisting>

      <para>
        Invoking an action on an application, with an action:
      </para>

      <programlisting>
        gapplication action org.example.fooview show-item '"item_id_828739"'
      </programlisting>
    </refsect2>

    <refsect2>
      <title>
        From the <varname>Exec</varname> lines of a <filename class='extension'>.desktop</filename> file
      </title>

      <para>
        The commandline interface of <command>gapplication</command> was designed so that it could be used
        directly from the <varname>Exec</varname> line of a <filename class='extension'>.desktop</filename>
        file.
      </para>

      <para>
        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.
      </para>

      <para>
        Consider the following example:
      </para>

      <programlisting>
        [Desktop Entry]
        Version=1.1
        Type=Application
        Name=Foo Viewer
        DBusActivatable=true
        MimeType=image/x-foo;
        Exec=gapplication launch org.example.fooview %F
        Actions=gallery;create;

        [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
      </programlisting>
    </refsect2>

    <refsect2>
      <title>From a script</title>

      <para>
        If installing an application that supports D-Bus activation you may still want to put a file in
        <filename class='directory'>/usr/bin</filename> so that your program can be started from a terminal.
      </para>

      <para>
        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
        <command>gapplication</command> to activate the application, open files, or invoke actions.
      </para>

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

      <programlisting>
        #!/bin/sh

        case "$1" in
          --help)
            echo "see 'man fooview' for more information"
            ;;

          --version)
            echo "fooview 1.2"
            ;;

          --gallery)
            gapplication action org.example.fooview gallery
            ;;

          --create)
            gapplication action org.example.fooview create
            ;;

          -*)
            echo "unrecognised commandline argument"
            exit 1
            ;;

          *)
            gapplication launch org.example.fooview "$@"
            ;;
        esac
      </programlisting>
    </refsect2>
  </refsect1>

  <refsect1>
    <title>See also</title>
    <para>
      <ulink url='http://standards.freedesktop.org/desktop-entry-spec/latest/'>Desktop Entry Specification</ulink>,
      <citerefentry>
        <refentrytitle>gdbus</refentrytitle>
        <manvolnum>1</manvolnum>
      </citerefentry>,
      <citerefentry>
        <refentrytitle>xdg-open</refentrytitle>
        <manvolnum>1</manvolnum>
      </citerefentry>,
      <citerefentry>
        <refentrytitle>desktop-file-validate</refentrytitle>
        <manvolnum>1</manvolnum>
      </citerefentry>
    </para>
  </refsect1>

</refentry>