Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

I need a ruby script that converts the contents of the clipboard to the md5 sum of the contents of the clipboard

Posted on 2011-03-13
17
Medium Priority
?
477 Views
Last Modified: 2012-05-11
It is all in the subject line.

I want to copy something.

Click on this script
the scipts performs an md5sum of what is on the clipboard and REPLACES it with just it's md5sum.

:)

thx  
0
Comment
Question by:TIMFOX123
  • 10
  • 7
17 Comments
 
LVL 12

Expert Comment

by:JESii
ID: 35130045
Try this
#!/usr/env ruby

require 'digest/md5'

require 'Win32API'
require 'win32/clipboard'
include Win32

data = Clipboard.get_data

hash = Digest::MD5.hexdigest(data)

Clipboard.set_data(hash)

Open in new window

0
 

Author Comment

by:TIMFOX123
ID: 35130520
Jessi

in `require': no such file to load -- win32/clipboard (LoadError)

Please refresh the mind of an old man .... :)

I have to run someting at the command line to get this code.  

thx.  
0
 

Author Comment

by:TIMFOX123
ID: 35130524
I am running rubymine :)

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:JESii
ID: 35133624
Of course; sorry... been a while, but as I recall you'll need:
     gem install win32-api
You may also need:
     gem install win32-clipboard

You can run this from the command line or within rubymine...
     
0
 

Author Comment

by:TIMFOX123
ID: 35146906
Jessii

I am still working this issue.   I am sure you gave good code, I just can not get my ruby mine to run it.  ( can not get it to see the gem ).  Rubymine has the best support in the sub 100$ software so I have pinged them.  

I am not ignoring this, I am just working the last step out with rubymine because it is not your issue.  

0
 
LVL 12

Expert Comment

by:JESii
ID: 35148374
I know what you mean; I've had some issues with RubyMine and gems, but they generally are responsive.

You might try just running this stand alone and make sure that you can get the basics running, and then you'll have a more complete bug report to the RM folks. I ran mine on Cygwin from the command line.
0
 

Author Comment

by:TIMFOX123
ID: 35160782
Jesii

can you give me a 101 on how to hand compile this ?

I am working the issue with rubygems but want to get this going.
Also this would be great for sending it to other desktops !!

0
 
LVL 12

Expert Comment

by:JESii
ID: 35165679
Sure... try this:
1. Create the file as 'clipboard.rb' in your working directory
2. gem install win32-api
3. gem install win32-clipboard
4. ruby clipboard.rb

Whatever was in the clipboard will now be hashed....
0
 

Author Comment

by:TIMFOX123
ID: 35166639
Jesii
this really is exciting ( I need this for deployment )

tell me more about:
2. gem install win32-api
3. gem install win32-clipboard

that will install it to the wrong place ?????  !!

so I put your script and the output of gem install in a directory and "life is good !!:
0
 

Author Comment

by:TIMFOX123
ID: 35166681
H:\rubypaste>gem install win32-api
ERROR:  Could not find a valid gem 'win32-api' (>= 0) in any repository
0
 
LVL 12

Expert Comment

by:JESii
ID: 35169844
Strange; try:
     gem search win32
and see what you get.
0
 

Author Comment

by:TIMFOX123
ID: 35180380
Jessi
great job and I am ready to award you all the points.  

One last question.  
I want to "prepend" the md5sum in the clipboard.
Lets say the md5sum is    2341234 and it is in the clipboard.
I want the clipboard to now have  ./fixit_ 2341234

Thank you soooooo much.


0
 

Author Comment

by:TIMFOX123
ID: 35180383
corection:

 ./fixit_ 2341234.sh  

 

0
 
LVL 12

Accepted Solution

by:
JESii earned 2000 total points
ID: 35180576
No problem; just change line 13 from:
     Clipboard.set_data(hash)
to use string concatenation to read:
     Clipboard.set_data('./fixit_' + hash + '.sh')

Alternatively, you could use string interpolation to do:
     Clipboard.set_data("./fixit_#{hash}.sh")

I've seen some comments that say string interpolation is faster, but in this case I don't think speed of execution could possibly be an issue, so use whichever feels most comfortable to you.
0
 

Author Comment

by:TIMFOX123
ID: 35180910
thank you so much.

If you know it or not, you create a sudo-database with this code that will be doing fixes on a large network.  Thank you soooooo much.

As I have said to other EE experts, you make me look really good.

thx so much.  
0
 

Author Closing Comment

by:TIMFOX123
ID: 35180919
this really works and really rocks.

I am using the md5sum of an error string to create a number.  The number is the shell file that fixes it
0
 
LVL 12

Expert Comment

by:JESii
ID: 35181032
You are very welcome; glad I could help!  And thank you for the points...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: narshlob
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between…
In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below: http://www.rubytips.org/2008/05/13/accessing-windows-api-fro…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month8 days, 2 hours left to enroll

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question