Utilities & Scripts

Hammers looking for nails

Small tools and scripts I’ve made to make my life easier, or sometimes more complicated. You know that Braess paradox, about how giving cars more or wider roads to fix traffic, just makes society shove more cars on there and break traffic? Hobby coding’s like that too sometimes.

Preview OpenRaster / ORA files instantly

I don’t always want to launch a whole image editor just to check how an ORA image looks. So I made a bash script for Linux. Can be added to a file manager’s (or image viewer’s) custom commands.

#!/bin/bash

temp_file=$(mktemp)
unzip -p "$1" mergedimage.png > "$temp_file"
xviewer "$temp_file"
sleep 1
trap 'rm "${temp_file}"' EXIT

Luckily, ORA’s usually have a fullsize preview of the whole image inside, updated by whatever app you’d be saving it from. So all this does is copy that merged image out to look at it.

Add Any Metadata to Any Files

This script isn’t very important, but it’s part of a process I’m working on, for having any tags and metadata on any file I want, not just obvious ones like photos or music, on Linux. All this script does, is give me a simple dialog box to set metadata quickly.

#!/bin/bash

f="$1"
b="${f##*/}"
name="${b%.*}"
id_1="${name#*.id_}"
id="${id_1%.*}"
ext="${b##*.}"
datadir=(~/mydata/mymetadata/)
fp=(~/mydata/mymetadata/"$id".txt)

if [ ! -f "$fp" ]; then
    zenity --info --title "ID Sidecar File Not Found!" \
    --text "No sidecar in <i>$datadir</i> \nfor <i>$f</i>" \
    --width 640
    exit
fi

fc=$(<"$fp")

if [ -z "$fc" ]; then
    fc="$b"
fi

cho=$(echo -e "$fc" | \
    zenity --text-info --editable --title "Editing Sidecar $id" \
    --width 500 --height 600 \
    --ok-label "Save" \
    --cancel-label "Cancel" \
    --extra-button "_Go To Sidecar" )
    # TODO: Button that lists all files found with this ID.
if [ $? == 0 ]; then # if Ok
    echo -e "$cho" > "$fp"
elif [ "$cho" == "_Go To Sidecar" ]; then
    dbus-send --type=method_call \
        --dest=org.freedesktop.FileManager1 \
        /org/freedesktop/FileManager1 \
        org.freedesktop.FileManager1.ShowItems \
        array:string:"file:$fp" string:""
else # Cancel
    exit
fi

It’s like the “sidecar file” methods, that associate files with similar names or that are “side-by-side” in the same folder. Except, here, I just use one part of the name, not the whole name, and not the path. That way, I can move the files around, from folder to folder, and not worry about breaking that connection.

The only way to break the connection here, is by removing that one bit of text in the filename, for the ID. It’s not even a real connection that the system understands, of course. It’s really just for me.

Carré