This script allows you to temporarily switch to the eraser tool by holding the S Pen side button while using Excalidraw inside Obsidian.
In Excalidraw, double-tapping the canvas can switch to the eraser, but it’s inconvenient to perform that gesture repeatedly. I created this script to make the workflow smoother: Draw → Hold S Pen button → Erase → Resume drawing
This script has only been tested on Samsung tablets with the S Pen, so stability may vary in other environments.
Due to system limitations, it is technically impossible to switch to the eraser only by pressing the S Pen button. Instead, the script uses button + one touch/drag as a trigger. Mouse right-click support is limited because this script was built primarily for S Pen usage.
- Active only while using the Freedraw tool
- While the S Pen button is held:
- Touch or slightly drag the canvas once → instantly switches to the eraser
- After you finish erasing and lift the pen:
- Automatically returns to the previous drawing tool (freedraw)
- In Excalidraw Automate, run:
Toggle Eraser on Right Click in Freedraw - Select a drawing tool (freedraw)
- Draw normally
- When you want to erase:
- Hold the S Pen side button
- Touch the screen once or lightly drag
→ Tool switches to eraser
- After one erase action:
- The tool automatically switches back to freedraw
- Ensure the Excalidraw plugin is installed.
- In Obsidian, go to:
Settings → Community Plugins → Excalidraw - In the Basic tab, check the path for
Excalidraw Automate script folder - Copy all repository files (except the README) into that folder
(Case-sensitive filenames!)
- Optimized for Samsung S Pen users.
- Some behaviors may not work correctly with a mouse.
- Automatic switching only occurs while the active tool is freedraw.
- Running the script again removes previously registered event listeners to avoid duplication.