Since Joplin doesn’t provide a way to take desktop screenshot and save it automatically, I thought to find a solution.
This depending on 2 components:
ShareX, a free and open source program that lets you capture or record any area of your screen,
Powershell, a task-based command-line shell and scripting language built on .NET.
First, create Powershell script to invoke API POST to Joplin:
I named it post.ps1 and saved it to C:\Users\rami\Downloads\. Following the script content:
# Joplin API endpoint and POST params
$url = "http://127.0.0.1:41184/notes?token=PLACE YOUR TOKEN HERE"
# Convert image to base64
$image_data_url = [convert]::ToBase64String((Get-Content $args[0] -Encoding byte))
#Forming API parameters
$params = -join("{ ""title"": ""Screenshot"", ""parent_id"": ""PLACE FOLDER ID HERE"", ""image_data_url"": ""data:image/png;base64,",$image_data_url,"""}")
#Make API POST request
Invoke-WebRequest $url -Method Post -Body $params
Note: you need to PLACE YOUR TOKEN HERE and PLACE FOLDER ID HERE.
Second, configure ShareX HotKey settings…
For example, customize “Capture region”
In “Task”, check “Override after capture settings” and select “Save image to file”, and “Perform actions”
In “Actions”, check “Override actions” and click “Add”. Fill-in the name “Post to Joplin”, “File Path” (where powershell.exe) and “Arguments” (-File full path+file name of the script created in FIRST step and don’t forget to add %input at the end)
For JoplinPortable users that have their post.ps1 file on the same drive as their ShareXPortable app I have found that you can omit the drive letter and colon from the path to the post.ps1 file so this feature can work as you move your USB drive between computers when the drive letter might change.
I have my post.ps1 file next to ShareX’s HotkeysConfig.json file:
<#
This Powershell script by rami.sedhom Dec 2019 layout altered by RAL 2020-04-14
at https://discourse.joplinapp.org/t/send-screenshot-to-joplin-windows/4918
Purpose: send screenshot taken by ShareX via PowerShell to Joplin Desktop (Windows OS)
For this script to run if PowerShell ExecutionPolicy is set to Restricted
have to run PowerShell as administrator and Set-ExecuitionPolicy RemoteSigned
Web clipper Service needs to be enabled
Two values need to be found:
1. The JoplinAuthorisationToken from the Tools > Options > Web Clipper > Advanced Options (a 128 digit no.)
2. The ID of the folder (notebook) where you want the screenshots stored (for me Scans under '_misc to be filed')
Run Insomnia, Get method, http://127.0.0.1:41184/folders, in the Query tab
add item, set name = "token" w/o quotes, set value = the JoplinAuthorisationToken
click send to get all the folders with their IDs (32 digit no.s)
#>
$JoplinAuthorisationToken = "********************************************************************************************************************************"
$DestinationFolderID = "********************************"
# Joplin API endpoint and POST params
$URL = "http://127.0.0.1:41184/notes?token=$JoplinAuthorisationToken"
# Convert image to base64 (variable name in CamelCase rather than underscores to highlight the difference in $params below)
$imageDataURL = [convert]::ToBase64String((Get-Content $args[0] -Encoding byte))
#Forming API parameters: here and here
$params = -join("{ ""title"": ""Screenshot"", ""parent_id"": ""$DestinationFolderID"", ""image_data_url"": ""data:image/png;base64,",$imageDataURL,"""}")
#Make API POST request
Invoke-WebRequest $URL -Method Post -Body $params
#Pause remove # when debugging
I found setting up ShareX the more difficult part of the job. Make sure you have followed rami's instructions carefully
Make sure to Enable the clipper service under Options -> Web Clipper
Get the folder id from Insomia app
On the Dashboard click the default Insomia document
Create a New Request ( CTRL+N), leave default "My Request" as its not important. then press Create
On the second column, you will see the method GET, enter the url http://127.0.0.1:41184/folders
3.1 Go to the Query tab, click the New Name as this will create a new entry
name = token
value = joplin Authorization token