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
462 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

9 Experts available now in Live!

Get 1:1 Help Now