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
449 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

16 Experts available now in Live!

Get 1:1 Help Now