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
457 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Ruby on Rails Installation Error 5 315
Java - confuse using abstract class and class 13 499
Install apt-get and ufw on Mac 10.8.4 6 996
Ruby error "undefined method" 6 78
I recently rediscovered rails when I needed a holiday project and decided to build a management dashboard for the company where I work.  With it being a project done in my free time, I could focus my time on learning the basics rather than trying to…
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
A short film showing how OnPage and Connectwise integration works.

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now