Page 1 of 1
Hash a File then copy the hash to clipboard
Posted: 30 Sep 2017 11:09
by pleiades
Hello everyone,
I like to hash a file then copy the hash to the clipboard after.
This is what I got, some codes are from Hash script I found here
Code: Select all
$File = get('SelectedItemsPathNames')
$Sha1 = hash('sha1', $File, '1')
copy $Sha1 ;
What is wrong with this?
Re: Hash a File then copy the hash to clipboard
Posted: 30 Sep 2017 11:18
by bdeshi
"What is wrong with this?"
Code: Select all
$File = get('SelectedItemsPathNames') // <-- 1. missing semicolon.
$Sha1 = hash('sha1', $File, '1') // <-- 1. missing semicolon 2. missing indentation makes this a separate subscript.
copy $Sha1 ; // <-- 1. missing indentation makes this a separate subscript 2. copy is for file/folders, you need copytext
A working solution:
Code: Select all
"Copy hash to clipboard"
$File = <selitem>; // <selitem> returns only the one currently selected item.
if (exists($File) == 1) { // exists($File) returns 1 if $File is a file, this avoids trying to hash a folder.
$Sha1 = hash('sha1', $File, 1);
copytext $Sha1;
}
Please at least glance over the scripting intro. (and look at the script reference for available commands and syntax):
Re: Hash a File then copy the hash to clipboard
Posted: 01 Oct 2017 17:48
by highend
And to do this with multiple files you just need to do the hashing in a foreach loop (and don't forget
to concatenate the hashes to copy them to the clipboard alltogether)
Re: Hash a File then copy the hash to clipboard
Posted: 02 Oct 2017 03:20
by pleiades
SammaySarkar, thank you for your help and code! I understand I need to learn scripting.
Highend, thank you for your advice, I will try that foreach loop.