Introducing a program to automatically edit text on the Windows 10 clipboard.
Another ditto article.
This function uses a sqlite database file generated from a clipboard manager called ditto. So please install it.
Ditto download | SourceForge.net
Please use the following bash script.
modifyWindowsClipboardText(){
while [ true ];
do
cp /mnt/c/Users/user/AppData/Roaming/Ditto/Ditto.db $TMPDIR/modifyWindowsClipboardText_Ditto.db
WindowsClipboardTextById="$(sqlite3 $TMPDIR/modifyWindowsClipboardText_Ditto.db "$(cat <<'EOT'
SELECT mText from Main
order by lDate desc
LIMIT 1 OFFSET 0
EOT
)")"
[[ "${WindowsClipboardTextById}" =~ ^https:\/\/user.xsrv.jp\/images\/ss\/ShareX_ScreenShot_.*\.(png|jpg|gif|mp4)$ ]] && {
echo "${WindowsClipboardTextById}" | sed -Ee "s/(.*)/!\[\1\]\(\1\)/g" | clip.exe ;
printf "Modified the Windows clipboard. : sharexUrl" ;
sleep 2s ; continue ;
} || {
: ;
}
echo -ne "$(isodate)\tNothing updated on the clipboard.\033[0K\r"
sleep 2s
done
}
isodate ()
{
date +%FT%T%Z
}
What I’m doing is, I use sharex, and when I take a screenshot, the URL is automatically copied to the clipboard. I usually share this URL with friends or paste it into article text, but at this time there’s the hassle of editing it to Markdown format from the text editor. Well, it’s something that can be done in about 5 seconds. I’m automating the work of replacing this URL with Markdown.
- Get the latest clipboard text (unique one) from the database
- If the text data matches a regular expression, process it accordingly and copy it to the clipboard
If you want to use it as a URL, you can copy the URL that’s second from ctrl + +. If you want to use Markdown, just paste the first one.
That’s what I’m doing.