Hash funcions for the Thunar Custom Actions
Welcome, Guest.
We just had a major upgrade and we are restoring board features. Your patience is appreciated while we work through these issues. --Spatry

Author Topic: Hash funcions for the Thunar Custom Actions  (Read 7044 times)

Offline misko_2083

  • Newbie
  • **
  • Posts: 10
Hash funcions for the Thunar Custom Actions
« on: January 12, 2015, 02:27:48 PM »
This is a bash script to calculate MD5, SHA-1, SHA-224, SHA-256, SHA-384 or SHA-512 hash sum.
It's desinged to be used as a Thunar Custom Action but it can be used like this
Code: [Select]
/usr/bin/checksum file.jpg. Depends on zenity ( sudo apt-get install zenity ).
A little GUI tool I've made, for all the XFCE fans.
Displays a dialog to choose the hash funcion and progress bar while it computes.

This is how to setup a Thunar Custom Action:
Name: Checksum
Description: Calculates  checksum.
Command: /usr/bin/checksum %f
Pattern: *
Appearance: Check all the boxes except Directories

save the script as checksum
make executable
copy the file to /usr/bin
The script:
Code: [Select]
#!/bin/bash
# Purpose:  Thunar Custom Action. Calculates hashes.
# Usage:     /usr/bin/checksum %f
# Author:    Misko_2083
# Date:       December 07, 2014
# Version:    1
# Licence GPLv2

file="$@"

MD5=(`echo "" | awk '{print "TRUE","MD5", $0}'`)
SHA1=(`echo "" | awk '{print "FALSE","SHA-1", $0}'`)
SHA224=(`echo "" | awk '{print "FALSE","SHA-224", $0}'`)
SHA256=(`echo "" | awk '{print "FALSE","SHA-256", $0}'`)
SHA384=(`echo "" | awk '{print "FALSE","SHA-384", $0}'`)
SHA512=(`echo "" | awk '{print "FALSE","SHA-512", $0}'`)

selection=$(zenity --list --radiolist --height=300 --title="Checksum" --text="File:  <b>${file##*/}</b>\nPick the hash funcion." --column="Pick" --column="Hash" "${MD5[@]}" "${SHA1[@]}" "${SHA224[@]}" "${SHA256[@]}" "${SHA384[@]}" "${SHA512[@]}")

# If Quit is clicked then exit
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
    exit 0
fi

echo $selection | grep "MD5" > /dev/null
if [ $? = 0 ];then
    md5sum "$file" | tee >(cut -d ' ' -f1 > /tmp/sum) |zenity --progress --title="MD5sum" --text="Calculating MD5 for:\n${file##*/}" --pulsate --auto-close

    # If Cancel is clicked then remove temporary file and exit
    if [ "${PIPESTATUS[2]}" -ne "0" ]; then
        rm /tmp/sum
        exit 0
    fi

    sum=`cat /tmp/sum`
    zenity --info --title="MD5sum" --text="MD5sum : $sum\nFile :          ${file##*/}"
    rm /tmp/sum
    exit 0
fi

echo $selection | grep "SHA-1" > /dev/null
if [ $? = 0 ];then
    sha1sum "$file" | tee >(cut -d ' ' -f1 > /tmp/sum) |zenity --progress --title="SHA-1" --text="Calculating SHA-1 for:\n${file##*/}" --pulsate --auto-close

    # If Cancel is clicked then remove temporary file and exit
    if [ "${PIPESTATUS[2]}" -ne "0" ]; then
        rm /tmp/sum
        exit 0
    fi

    sum=`cat /tmp/sum`
    zenity --info --title="SHA-1" --text="SHA-1: $sum\nFile :    ${file##*/}"
    rm /tmp/sum
    exit 0
fi

echo $selection | grep "SHA-224" > /dev/null
if [ $? = 0 ];then
    sha224sum "$file" | tee >(cut -d ' ' -f1 > /tmp/sum) |zenity --progress --title="SHA-224" --text="Calculating SHA-224 for:\n${file##*/}" --pulsate --auto-close

    # If Cancel is clicked then remove temporary file and exit
    if [ "${PIPESTATUS[2]}" -ne "0" ]; then
        rm /tmp/sum
        exit 0
    fi

    sum=`cat /tmp/sum`
    zenity --info --title="SHA-224" --text="SHA-224 : $sum\nFile :         ${file##*/}"
    rm /tmp/sum
    exit 0
fi

echo $selection | grep "SHA-256" > /dev/null
if [ $? = 0 ];then
    sha256sum "$file" | tee >(cut -d ' ' -f1 > /tmp/sum) |zenity --progress --title="SHA-256" --text="Calculating SHA-256 for:\n${file##*/}" --pulsate --auto-close

    # If Cancel is clicked then remove temporary file and exit
    if [ "${PIPESTATUS[2]}" -ne "0" ]; then
        rm /tmp/sum
        exit 0
    fi

    sum=`cat /tmp/sum`
    zenity --info --title="SHA-256" --text="SHA-256 : $sum\nFile :         ${file##*/}"
    rm /tmp/sum
    exit 0
fi

echo $selection | grep "SHA-384" > /dev/null
if [ $? = 0 ];then
    sha384sum "$file" | tee >(cut -d ' ' -f1 > /tmp/sum) |zenity --progress --title="SHA-384" --text="Calculating SHA-384 for:\n${file##*/}" --pulsate --auto-close

    # If Cancel is clicked then remove temporary file and exit
    if [ "${PIPESTATUS[2]}" -ne "0" ]; then
        rm /tmp/sum
        exit 0
    fi

    sum=`cat /tmp/sum`
    zenity --info --title="SHA-384" --text="SHA-384 : $sum\nFile :         ${file##*/}"
    rm /tmp/sum
    exit 0
fi

echo $selection | grep "SHA-512" > /dev/null
if [ $? = 0 ];then
    sha512sum "$file" | tee >(cut -d ' ' -f1 > /tmp/sum) |zenity --progress --title="SHA-512" --text="Calculating SHA-512 for:\n${file##*/}" --pulsate --auto-close

    # If Cancel is clicked then remove temporary file and exit
    if [ "${PIPESTATUS[2]}" -ne "0" ]; then
        rm /tmp/sum
        exit 0
    fi

    sum=`cat /tmp/sum`
    zenity --info --title="SHA-512" --text="SHA-512 : $sum\nFile :         ${file##*/}"
    rm /tmp/sum
    exit 0
fi

Greats everyone,  :)
Misko_2083 (Linux Lite dev)

Offline lcRONOS

  • I will run all the Operating Systems!
  • Staff Member
  • ********
  • Posts: 751
Re: Hash funcions for the Thunar Custom Actions
« Reply #1 on: January 14, 2015, 11:11:42 PM »
Great find misko_2083 :) If I knew more about programming I'd try to set it up to work with Dolphin, maybe that'll be a project for me later on.  Thanks for sharing it with the community.
Laptop: HP Pavilion 15t, quadboot Obarun Linux, macOS 10.13, TrueOS, Windows 10
Desktop: Dell Inspiron 660, dualboot Artix Linux,Windows 1

Offline misko_2083

  • Newbie
  • **
  • Posts: 10
Re: Hash funcions for the Thunar Custom Actions
« Reply #2 on: January 17, 2015, 11:08:35 AM »
Sure no problem :)
To use this in Dolphin just save the script as I've described in my previous post.
Make the file executable, and copy the file to /usr/bin, you'll need elevated privileges or root to do that.
Make sure you have zenity installed.
Now you can set the Dolphin service menu with your text editor.
Open your text editor and paste this inside:
Code: [Select]
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KonqPopupMenu/Plugin,all/allfiles
Actions=Checksum;
X-KDE-AuthorizeAction=shell_access

[Desktop Action Checksum]
Exec=/usr/bin/checksum %f
Icon=accessories-calculator
Name=Checksum
X-Ubuntu-Gettext-Domain=desktop_kdebase
Save the file as
/home/user/.kde/share/kde4/services/Checksum.desktop
You might need to reopen Dolphin. It should show up as 'Checksum' when you right-click on any file.
Cheers :)

Offline glsmaxx

  • Full Member
  • ****
  • Posts: 274
  • Old Dog Learnin' New Tricks
Re: Hash funcions for the Thunar Custom Actions
« Reply #3 on: March 09, 2016, 08:37:37 AM »
Just added the script to my custom actions in Thunar.
Thanks
Running Manjaro-XFCE  &  Arch-XFCE
           Are There Any Others?

Offline Spatry

  • Benevolent Dictator
  • Administrator - Sysop
  • **********
  • Posts: 5475
  • Cup of Linux Founder
    • Cup of Linux
Re: Hash funcions for the Thunar Custom Actions
« Reply #4 on: March 09, 2016, 11:22:50 PM »
Thanks for your contribution misko! Cheers!
Windows assumes the user is an idiot... Linux DEMANDS Proof!

Offline kevjonesin

  • Newbie
  • **
  • Posts: 4
  • there's only now, yet tomorrow keeps happening
    • Digital Alchemy
Re: Hash funcions for the Thunar Custom Actions
« Reply #5 on: March 10, 2016, 02:39:16 PM »
Thanks Misko! Handy little gadget to have in my thunar.
Linux Mint 17 Xfce; also Manjaro 15.10 LXQt; dabbling with MX; antiX; MintPPC (Debian PPC base); and various Puppy Linux (mostly Tahrpup) [all running on a variety of older hardware]

Offline CwF

  • Elite Member
  • *****
  • Posts: 378
Re: Hash funcions for the Thunar Custom Actions
« Reply #6 on: January 09, 2017, 10:28:53 AM »
Thank you much. I'm here, but google found this gem for me. After a few of these details, Thunar is great.

Offline al0o0z

  • Newbie
  • **
  • Posts: 1
Re: Hash funcions for the Thunar Custom Actions
« Reply #7 on: September 30, 2018, 11:23:56 PM »
Thanks for this great tool :) I was searching for something like this.