How to open a new file from the command line with Inkscape
I can't find how to open a new svg document with Inkscape, simply from the terminal.
If the document specified as argument (or via -f
) does not exist, there is just an error saying it doesn't exist, and then it opens an unsaved new document.
I tried using the verb FileSaveAs
like this for example:
inkscape --verb FileSaveAs mynewfile.svg
but FileSaveAs does not take arguments, it just opens the graphical window for this action.
I might be persnickety, but I would find it more convenient to be able to create a new file directly from the command line instead of having to launch this window and click to the right directory...
Solution 1:
To my surprise, there seems to be no option in Inkscape to produce a new file from cli!
How to create the option?
As always, if it doesn't exist, it can be made:
- Open
Inkscape
, create a new filedrawing.svg
- Save this file anywhere
-
Copy the code below into an empty file, save it as
newinkscape
(no extension) in~/bin
. Create the directory if it doesn't exist yet.#!/bin/bash sample="/path/to/drawing.svg" dr=$1 cp "$sample" "$dr" inkscape "$dr"
Make the script executable
-
Replace in the line:
sample="/path/to/drawing.svg"
The path by the path to your sample file.
Log out and back in, now:
newinkscape /path/to/newfile.svg
will open a new empty Inkscape
file, saved in the location you used in the command.
Solution 2:
Well, I've been wondering about this same thing for years (especially since touch mynewfile.svg; inkscape mynewfile.svg
causes InkscapeApplication::document_open: Failed to open: /path/to/mynewfile.svg ; ConcreteInkscapeApplication::on_open: failed to create document!
) - and finally, after consulting https://wiki.inkscape.org/wiki/index.php/Using_the_Command_Line, I found it:
inkscape --without-gui --actions="file-new; export-area-page; export-filename:test.svg; export-do;"
For instance, to test under Ubuntu 18.04:
$ inkscape --version
Inkscape 1.0.1 (1.0.1+r73)
Pango version: 1.40.14
$ ls -la test.svg
ls: cannot access 'test.svg': No such file or directory
$ inkscape --without-gui --actions="file-new; export-area-page; export-filename:test.svg; export-do;" 2>/dev/null && ls -la test.svg
-rw-r--r-- 1 user user 1134 Sep 15 05:53 test.svg
$ cat test.svg
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="svg10"
width="100%"
height="100%"
viewBox="-1 -1 1 1">
<metadata
id="metadata16">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs14" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="640"
inkscape:window-height="480"
id="namedview12" />
</svg>