Tuesday | 30 APR 2024
[ previous ]
[ next ]

Screenshots

Title:
Date: 2024-01-02
Tags:  blog

I think having screenshots is more important than being able to run my old projects. I don't really care about the running part, what I really want is to see my old work to go back to that time in my memories.

It'd be nice to be able to run things easily but it's not a hard requirement, at least not for me. That's why I've been struggling with my editor and taking screenshots for so long.

I've been trying to figure out how I could get screenshots into my [EVA] editor and I've looked at a few different ways but none really jumped out at me. There was some that relied on specific terminal emulators to pass data through as raw text but that would require specific emulators. The option I'm currently going to play with is the one that is going to be outlined in this blog post.

I had wanted to keep the implementation of uploading images on my server so that I could use any computer to do the screenshoting. I've realized now that I should just bite the bullet and do it client side.

The core logic is that I'll take a screenshot, save it to a file, hash it and get the md5sum of it, rename the file and then scp it over to my server. I would then update the paste buffer with the shortcode for images so that I could immediately paste it into EVA.

The bash script to do this is quite simple and it does annoy me that I had to do it this way but I think it's the cleanest way so far. It is also a simple enough script that modifying it for xclip would be straightforward.

#!/usr/bin/env bash
set -e

focusedWindow=$(swaymsg -t get_tree | jq '.. | select(.focused?) | .name'
windowName='"EVA"'

if [[ "$focusedWindow" != "$windowName"  ]];
then
   exit 1
fi

tmpFile=/tmp/last-eva-paste.png

wl-paste > $tmpFile

md5=($(md5sum $tmpFile))

mv $tmpFile /tmp/$md5.png 

scp /tmp/$md5.png username@192.168.11.11:/home/BLOG/HTML/$md5.png

firefox /tmp/$md5.png

wl-copy "![image](/images/$md5.png)" --primary

YDOTOOL_SOCKET=/tmp/.ydotool_socket ydotool type "![image](/images/$md5.png)"

I open the screenshot in firefox so I can see what I uploaded to my server and the wl-copy and wl-paste commands come from wl-clipboard.

I have a couple of extra lines so that my bash script only runs if the focused window is my EVA window and I use ydotool to automatically type out the image shortcode. This way I can be sitting in my editor and take a screenshot and put it on my blog with a single shortcut that's bound to this script.

It's a bit longwinded but hopefully the below image appears!

image

It did, or should have.

I set up a keybinding in my sway config so that I could get something into my clipboard and then it would execute the above script.

I'll need to use it for a bit before I can say that I'm happy with it but I do think it's a simple and clean workflow.

My dream solution would be to copy something and have it in my clipboard, do Ctrl V and then EVA should take over and automatically grab the clipboard content and save it to the file and inject in the image shortcode.

Incoming Links

  1. [ ydotool ]