Difference between revisions of "Using the Command Line"

From Inkscape Wiki
Jump to navigation Jump to search
(→‎Changes from 0.92: Update with new info.)
Line 74: Line 74:
 
= Changes from 0.92 =
 
= Changes from 0.92 =
  
* Each command-line argument can be used only once.
+
== General Changes ==
: In 0.92, command-line arguments can be repeated and are processed in the order they appear:
+
* Each command-line argument can be used only once. The order does not effect processing. Instead, some arguments, e.g. <code>--verbs</code>, can have a semicolon separated list of values:
: '''inkscape --select=MyStar --verb ObjectFlipVertically --verb FileSave --verb FileClose MyStar.svg'''
+
: <code>inkscape --select=MyStar --verb "ObjectFlipVertically;FileSave;FileClose" MyStar.svg</code>
: will open the file '''MyStar.svg''', select the object with ''id'' '''MyStar''', flip the object vertically, save the file and then close it.
+
* <code>xverbs</code> are no longer supported. They are (will be) replaced by <code>actions</code>.
: Post 0.92, command-line arguments cannot be repeated and the order does not effect processing. Instead, some arguments, e.g. '''--verbs''', can have a semicolon separated list of values:
+
* Inkscape can now take more than one input file, as in <code>inkscape filename1.svg filename2.svg</code>.
: '''inkscape --select=MyStar --verb "ObjectFlipVertically;FileSave;FileClose" MyStar.svg'''
+
* The <code>--export-id</code> argument now supports a semicolon separated list of objects, each one will be exported separately.
* '''xverbs''' are not supported. They are (will be) replaced by ''actions''.
+
* The <code>--query-id</code> argument now supports a comma separated list of objects. Any geometry query (e.g. <code>--query-x</code>) will return a comma separated list of values corresponding to the list of objects in <code>--query-id</code>.
* The command-line option '''--verb''' is deprecated, use '''--actions''' instead:
+
* In export mode, to overwrite a file, one must use <code>--export-overwrite</code>, otherwise a new filename will be generated: file.svg -> file_out.svg
: '''inkscape --select=MyStar --actions="ObjectFlipVertically;FileSave;FileClose" MyStar.svg'''
+
* The option <code>--select</code> now accepts a comma separated list of object IDs instead of only a single ID.
: Eventually all verbs will be replaced by actions. Temporarily, any ''verb'' can be used as an ''action''.
+
 
: Note, most verbs require a GUI (even if they don't use it). To close the GUI automatically at the end of processing, use '''--batch-process'''.
+
 
* The '''--export-id''' argument now supports a semicolon separated list of objects, each one will be exported separately.
+
== Deprecations and Replacements ==
* The '''--query-id''' argument now supports a comma separated list of objects. Any geometry query (e.g. '''---query-x''') will return a comma separated list of values corresponding to the list of objects in '''--query-id'''.
+
 
 +
* The command-line option <code>--verb</code> is deprecated, use <code>--actions</code> instead:
 +
: <code>inkscape --select=MyStar --actions="ObjectFlipVertically;FileSave;FileClose" MyStar.svg</code>
 +
: Eventually all verbs will be replaced by actions. Temporarily, any <code>verb</code> can be used as an <code>action</code>.
 +
: Note, most verbs require a GUI (even if they don't use it). To close the GUI automatically at the end of processing, use <code>--batch-process</code>.
 +
* <code>--export-png</code>, <code>--export-ps</code>, <code>--export-eps</code>, <code>--export-pdf</code>, <code>--export-emf</code>, <code>--export-wmf</code>, <code>--export-xaml</code> must be replaced by one of:
 +
** <code>--export-file=MyOutput.xxx</code> to export a single file of type xxx
 +
** <code>--export-type="xxx"</code> to batch export a list of input files to type xxx.
 +
* <code>--usage</code> option was removed
 +
* '''Attention''': the <code>-p</code> option for printing has changed meaning! It now means 'pipe', see below. There is no replacement available for printing.
 +
* The option <code>--file</code>, <code>-f</code> has been dropped. To select a file to open, simply write it as the first argument to the <code>inkscape</code> command.
 +
 
 +
== New options ==
 +
 
 +
* <code>--action-list</code>: list available actions
 +
* <code>-p, --pipe</code>: Reads input file from standard input (stdin).
 +
* <code>--pdf-page=PAGE</code>: Imports the given page of a pdf file. Numbering starts with 1.
 +
* <code>--pdf-poppler</code>: Imports a pdf via an external (poppler with cairo backend) library. Text consists of groups containing cloned glyphs where each glyph is a path.
 +
Images are stored internally. Meshes cause entire document to be rendered as a raster image.
 +
* <code>--batch-process</code>: Close GUI when done
 +
* <code>--export-file=MyOutput.xxx</code>: Export a single file of type xxx (svg, png, ps, eps, pdf, emf, wmf, xaml)
 +
* <code>--export-type="xxx"</code>: Batch export a list of input files to type xxx.
 +
* <code>--export-ps-level>={2,3}</code>: choose PostScript level

Revision as of 13:29, 27 December 2019

This is a Work in Progress.

Background

Starting after the release of the 0.92.x series, Inkscape's code is undergoing a major rewrite with the dual goals of making it more powerful and flexible for the user while making it easier for the developer. This is a long term process and it will be awhile before we see the full benefits.

As a first step, we've started to use the latest Gtk 3 application code for Inkscape 1.0 which has resulted in some changes in how the command line works.

For the command line parameters for Inkscape versions up to 0.92.x, please check the corresponding output of inkscape --help on the command line.

What can you do with the command line?

Print out information

  • Help (list of command line options): inkscape --help or inkscape -?
  • Inkscape version: inkscape --version
  • Extension directory: inkscape --extension-directory or inkscape -x
  • List of available verbs (very long): inkscape --verb-list
  • List of available actions: inkscape --action-list

Query geometry information

  • Find the x position of a set of objects: inkscape --query-id="MyTriangle,MySquare" --query-x my_file.svg
This will return, for example:
200,300
  • Query the geometry of all objects: inkscape --query-all
This will return, for example (id,x,y,width,height):
MySvg,0,0,600,600
MyGroup,100,100,300,300
MyTriangle,120,120,100,80
MySquare,150,150,50,50

Export files

Via export options

Use of export options will suppress the GUI. All files listed on the command line will be opened, processed according to export options. and then be closed.

Some options are exclusive.

  • If both --export-filename and --export-type are given, the file name extension must match the type.
  • Only one of --export-area, --export-area-page, -export-area-drawing, --export-use-hints will be used to determine the export area. (Which one?)

Examples

  • Simple export of a PNG: inkscape --export-type="png" my_file.svg
This will produce a PNG with a name my_file.png
  • Export one object from the file to a PNG: inkscape --export-type="png" --export-id="MyTriangle" my_file.svg
This will produce a PNG with a file name my_file_MyTriangle.png which tightly wraps the object. Objects that extend into the exported area will be shown.
  • Export one object from the file to a PNG, hiding all other objects: inkscape --export-type="png" --export-id="MyTriangle" --export-id-only my_file.svg
This will produce a PNG with a file name my_file_MyTriangle.png which tightly wraps the object. Only the triangle is shown.
  • Export more than one object at a time to PNG files: inkscape --export-type="png" --export-id="MyTriangle,MyRectangle" my_file.svg
This will produce two PNG files, one tightly wrapping the triangle, the other the rectangle.
  • Export more than one object to SVG files: inkscape --export-type="svg" --export-id="MyTriangle,MyRectangle" --export-id-only my_file.svg CRASH: FIXME
This will produce two SVG files, one with just the triangle, the other with just the rectangle.

Via actions

Use of export options and actions can be mixed. (How?) All export options have matching actions (remove the '--' in front of the option and replace '=' with ':'). If only actions are used, either --without-gui or --batch-process must be used (due to our code structure, most verbs require the GUI to be present even if not used). All files on the command line will be opened, processed according to actions options, and then closed. Export can be forced at any point with the export-do action. This allows one to do multiple exports on a single file.

Examples

  • inkscape --without-gui --actions="export-id:MyTriangle; export-id-only; export-background:purple; export-filename:triangle_purple.png; export-do; export-background:red; export-filename:triangle_red.png" my_file.svg
This will export the object with the id MyTriangle with a purple background to the file triangle_purple.png and with a red background to the file triangle_red.png. (Note: there is an implicit file export at the end.
  • inkscape --without-gui --actions="export-id-only; export-id:Triangle; export-filename:action_triangle.png; export-do; export-id:Path; export-filename:action_path.png" export_test.svg
Exports the objects Triangle and Path to different files.

Modify files

  • inkscape --actions="select:Triangle; ObjectFlipVertically; export-filename:flipped-triangle.svg; export-do; EditUndo; select:Path; ObjectFlipHorizontally; export-filename: flipped-path.svg; export-do; EditUndo; FileClose" export_test.svg
Flip the triangle, save the result. Undo the flip, then flip the path, save the result. Undo the flip and close the file. (At the moment, one must undo any changes to avoid popping up a dialog warning about unsaved changes.)

Changes from 0.92

General Changes

  • Each command-line argument can be used only once. The order does not effect processing. Instead, some arguments, e.g. --verbs, can have a semicolon separated list of values:
inkscape --select=MyStar --verb "ObjectFlipVertically;FileSave;FileClose" MyStar.svg
  • xverbs are no longer supported. They are (will be) replaced by actions.
  • Inkscape can now take more than one input file, as in inkscape filename1.svg filename2.svg.
  • The --export-id argument now supports a semicolon separated list of objects, each one will be exported separately.
  • The --query-id argument now supports a comma separated list of objects. Any geometry query (e.g. --query-x) will return a comma separated list of values corresponding to the list of objects in --query-id.
  • In export mode, to overwrite a file, one must use --export-overwrite, otherwise a new filename will be generated: file.svg -> file_out.svg
  • The option --select now accepts a comma separated list of object IDs instead of only a single ID.


Deprecations and Replacements

  • The command-line option --verb is deprecated, use --actions instead:
inkscape --select=MyStar --actions="ObjectFlipVertically;FileSave;FileClose" MyStar.svg
Eventually all verbs will be replaced by actions. Temporarily, any verb can be used as an action.
Note, most verbs require a GUI (even if they don't use it). To close the GUI automatically at the end of processing, use --batch-process.
  • --export-png, --export-ps, --export-eps, --export-pdf, --export-emf, --export-wmf, --export-xaml must be replaced by one of:
    • --export-file=MyOutput.xxx to export a single file of type xxx
    • --export-type="xxx" to batch export a list of input files to type xxx.
  • --usage option was removed
  • Attention: the -p option for printing has changed meaning! It now means 'pipe', see below. There is no replacement available for printing.
  • The option --file, -f has been dropped. To select a file to open, simply write it as the first argument to the inkscape command.

New options

  • --action-list: list available actions
  • -p, --pipe: Reads input file from standard input (stdin).
  • --pdf-page=PAGE: Imports the given page of a pdf file. Numbering starts with 1.
  • --pdf-poppler: Imports a pdf via an external (poppler with cairo backend) library. Text consists of groups containing cloned glyphs where each glyph is a path.

Images are stored internally. Meshes cause entire document to be rendered as a raster image.

  • --batch-process: Close GUI when done
  • --export-file=MyOutput.xxx: Export a single file of type xxx (svg, png, ps, eps, pdf, emf, wmf, xaml)
  • --export-type="xxx": Batch export a list of input files to type xxx.
  • --export-ps-level>={2,3}: choose PostScript level