Send screenshot to Joplin (Windows)

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:

  1. ShareX, a free and open source program that lets you capture or record any area of your screen,
  2. 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…

  1. For example, customize “Capture region”
    ShareX_-_Hotkey_settings_20191230192957
  2. In “Task”, check “Override after capture settings” and select “Save image to file”, and “Perform actions”
  3. 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)
    ShareX_-_Actions_20191230224156
    It should look something similar to this:

Now, whenever you take screenshot with (Ctrl+Print Screen), it’ll be saved in Joplin.

5 Likes

where do I find the PLACE FOLDER ID?

I use insomnia rest client to get such information from Joplin api.

Using insomnia:

  1. Select GET method
  2. Use url = http://127.0.0.1:41184/folders
  3. In Query tab, add item name = token and item value = your token
  4. Click Send

You will get all your folders with folder IDs.

For newbies like me who struggle to get this working:

  1. The ‘token’ refered to in ‘PLACE YOUR TOKEN HERE’ is the Joplin Authorisation token found in Tools > Options > Web Clipper > Advanced Options

  2. The WebClipper Sevice needs to be running

  3. If PowerShell ExecutionPolicy is set to Restricted, need to to run PowerShell as administrator and Set-ExecuitionPolicy RemoteSigned

1 Like

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:

X:\PortableApps\ShareXPortable\Data\post.ps1
X:\PortableApps\ShareXPortable\Data\HotkeysConfig.json

so ShareX - Actions - Arguments field is:

-File \PortableApps\ShareXPortable\Data\post.ps1 %input

1 Like

Hi,

I tried a full day to set this up, but it is not working. can anyone help me,

Is it working for you now?

I did everything replace the folder id, toke , everything

But nothing is working, can you please help me

It is not working for me ,

can you please help me ,

can you please tell is it working for you now

It is working for me

Hi

Can you please send me the script .Please i think there is something wrong with my script .

Please

<#
 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

1 Like

I got stuck using the Insomia app but your post help me figure it out.

Here is a step by step to get the folder id

Pre-requisite

  1. Download and Install Insomia app
  2. Make sure to Enable the clipper service under Options -> Web Clipper

Get the folder id from Insomia app

  1. On the Dashboard click the default Insomia document
  2. Create a New Request ( CTRL+N), leave default "My Request" as its not important. then press Create
  3. 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
  4. Press Send

For me it is creating a file in the folder specified but no image is visible. I cant figure out the problem