Hash a File then copy the hash to clipboard

Discuss and share scripts and script files...
Post Reply
pleiades
Posts: 52
Joined: 13 Aug 2016 10:36

Hash a File then copy the hash to clipboard

Post 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?

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Hash a File then copy the hash to clipboard

Post 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):

Code: Select all

::rtfm 'idh_scripting.htm';
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Hash a File then copy the hash to clipboard

Post 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)
One of my scripts helped you out? Please donate via Paypal

pleiades
Posts: 52
Joined: 13 Aug 2016 10:36

Re: Hash a File then copy the hash to clipboard

Post 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.

Post Reply