Switching between Markdown and WYSIWYG - Keyboard Shortcut - Xubuntu/Ubuntu 20.04

Hey guys,

Just sharing a bash solution for setting up quick switching between markdown and wysiwyg for xubuntu or ubuntu (probably works with other systems using xdotools and wmctrl) to get your system to dynamically click on that top right button (regardless of workspace, size and position of the joplin window)

I initially searched but the solution here but no solution for the time being on the application.

This can be binded to a system wide button specifically for joplin to quickly jump back to typing / swapping modes.

Save this script somewhere and bind your keyboard button from the gui side to call this script, and it will swap to the workspace where your joplin is on, then swap modes, and you can immediately start typing. I binded the key to "Ctrl + \ ".

You will need to change the tgtx and tgty because the position of your button may be different (as I do not have title bars)

The script is kinda scrappy so if someone can help me optimize the bash script to less lines/less variables, function calls or use of memory, that would be greatly appreciated. Thanks ahead of time.

Cheers all


chid=($(wmctrl -l | grep -i joplin | awk '{print $1}')) # Window ID
winid=($(wmctrl -l | grep -i joplin | awk '{print $2}')) # Workspace ID

wmctrl -s $winid # Swap to Workspace
usableid=($(printf %i $chid)) # Reformat for xdotools

rawinfo="$(xdotool getactivewindow getwindowgeometry $usableid| tail -2 | awk '{print $2}')" # Get window Raw info

posraw=($(echo "$rawinfo" | head -1|tr ',' ' ')) #Splitting xpos and ypos into array
sizeraw=($(echo "$rawinfo" | tail -1|tr 'x' ' ')) #Splitting xsize and ysize into array

# Adjust accordng to your button position relative to your window's absolute position

tgtx="$((${posraw[0]} + ${sizeraw[0]} - 50))"  # "50" here is the distance from the right of the window to the button from the right side
tgty="$((${posraw[1]}+88))"  # 88 is the distance from the top of the dwindow to the bottom

# Hit the bottom left corner of the joplin "typable text area" to start typing

# Store existing mouse position

mouseraw=($(xdotool getmouselocation))
mousex=($(echo ${mouseraw[0]} | tr ':' ' '))
mousey=($(echo ${mouseraw[1]} | tr ':' ' '))

xdotool mousemove $tgtx $tgty
xdotool click 1
sleep 0.1 # intended because the 
xdotool mousemove $tgtxr $tgtyr
xdotool click 1

# Restore original Mouse Position
xdotool mousemove $mousexraw $mouseyraw

exit 0