with joplin terminal you can do:

joplin --profile ~/.config/joplin-desktop mknote test_attachment

add an attachment by

joplin --profile ~/.config/joplin-desktop attach <note> <file>

to spot the note id we do

joplin --profile ~/.config/joplin-desktop ls -l -t n -n 1 -f json

explanation :

ls -l 

like the command line :wink:

-t n

means you just want to list "note" (vs task with -t t )

-n 1 

means you want the 1irst one only

-f json 

-f is the output format, here json
the main pro of -f json is to be able to grab the stdout easily and avoid to use some |cut -d ''

here is my final output

joplin --profile ~/.config/joplin-desktop ls -t n -n 1 -s created_time -f json

[{"id":"7c46776072704f679a73d3e5eeeb4e14","title":"test_attachment","body":"","is_todo":0,"todo_completed":0,"parent_id":"e424345758da42e0be3d7a7574101a4e","updated_time":1536861769606,"user_updated_time":1536861769606,"user_created_time":1536861499476,"encryption_applied":0,"type_":1}]

then I can use attach

joplin --profile ~/.config/joplin-desktop attach 7c467 ~/Images/P_20180902_184400.jpg

you could notice that I did not provide the complet note ID because joplin ls -l display the first 4 car so you could use also 4 car or more

now

joplin --profile ~/.config/joplin-desktop ls -t n -n 1 -s created_time -f json
[{"id":"7c46776072704f679a73d3e5eeeb4e14","title":"test_attachment","body":"![P_20180902_184400.jpg](:/662ad00e97c540c890e8c8fdc00b644d)\n\n","is_todo":0,"todo_completed":0,"parent_id":"e424345758da42e0be3d7a7574101a4e","updated_time":1536861769606,"user_updated_time":1536861769606,"user_created_time":1536861499476,"encryption_applied":0,"type_":1}]

The image will be added at the end of the note.

Now, If you plan to deal with the image position, I wont export anything from the database into markdown file. Instead I will read the text database and wrap the joplin terminal to build the notes the way I want.

For example

In your perl script:

  1. you could split the text body in 3 pieces for example, to put the image after each piece of body
  2. run joplin mknote title1
  3. grab the note ID with
joplin --profile ~/.config/joplin-desktop ls -t n -n 1 -s created_time -f json
  1. joplin set <noteid_found_in_point_3> body body_piece1
  2. joplin attach <noteid_found_in_point_3> /path/to/image1.jpg
  3. repeat 4 and 5 for body_piece2 and body_piece3 and each attachment

ps : i'm not sure of the result with

joplin set <noteid_found_in_point_3> body body_piece1 

It's possible that with

joplin set <noteid_found_in_point_3> body body_piece2

the 2nd piece override the complet body.
In that case, to concatenate the content of the existing body, redo

joplin --profile ~/.config/joplin-desktop ls -t n -n 1 -s created_time -f json

to grab the "body" and then you could update the body withtout risk

1 Like