Welcome Guest.   Make a donation to an author on the site November 29, 2014, 03:57:06 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Check out and download the GOE 2007 Freeware Challenge productivity tools.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: CHS tip - retain last clip's formatting with an AutoHotKey workaround script  (Read 2109 times)
IainB
Supporting Member
**
Posts: 4,881


Slartibartfarst

see users location on a map View Profile Give some DonationCredits to this forum member
« on: February 28, 2012, 06:42:38 AM »

This tip is about something that I have found to be a very handy time-saver.
I use CHS a lot, and sometimes I want to:
(a) first, paste as plain (unformatted) text something that I have just copied, into a document.
(b) second, paste the same text - but with all its original formatting - into a different document.
I can't do this with CHS.
This post explains why, and how to get a reasonably good workaround to that, using an AHK script.

Using CHS, when you copy something (text or image) to the clipboard, it gets saved in CHS as either image or text.
An image on its own is saved as an image, in CHS.
Text is saved as text without the formatting, in CHS.
Images and text copied combined in a single clip together are saved as either image, or text, depending on your CHS priority setting.
But whatever was in the clipboard buffer (image, or text, or image and text) remains as is - including any text formatting - until it is overwritten by the next copy action or by CHS.

If you paste the last clip that was copied into the clipboard buffer, then it is pasted intact from the clipboard buffer, together with its formatting (includes any objects in the clip also).

But, if you use the CHS command to paste it as plain (unformatted) text, then CHS apparently removes the formatting - effectively overwriting the clipboard buffer with plain (unformatted) text - and that buffer's content is then pasted into your document.
Having done that, if you then want to paste the formatted text anywhere else - you cannot paste it. This is because the formatted text does not exist in the clipboard buffer, having been overwritten by the plain (unformatted) text. (This can be very frustrating at times!)

There is an AutoHotKey script which provides a handy and time-saving workaround for this.
To use it, first disable any keyboard hotkeys that may be set in CHS to force a plain (unformatted) text paste. So CHS does not change whatever text and formatting it finds in the clipboard buffer - i.e., it always pastes what is in the buffer.

The AHK script intercepts these key combo inputs, and takes action as shown:
  • Ctrl+Shift+V: this causes the formatted text to be pasted.
  • Ctrl+V: this causes the plain (unformatted) text to be pasted.

(You can change the script to use other key combos, if you want. These particular ones suit the ergonomics of my way of working to a "T".)

The AHK script works thus:
1. When Ctrl+Shift+V is pressed: the keyboard string "Ctrl+V" is passed to the system, causing a normal (unmodified) paste of whatever is in the clipboard buffer.
2. When Ctrl+V is pressed:
(a) the current as-copied formatted text contents (alas, minus any accompanying image objects) of the clipboard buffer are saved intact;
(b) the contents of the clipboard buffer are overwritten with the plain (unformatted) text (i.e., formatting is removed);
(c) the keyboard string "Ctrl+V" is passed to the system, causing a normal (unmodified) paste of whatever is in the clipboard buffer.
(d) the saved as-copied formatted text is restored to the clipboard buffer (minus any accompanying image objects that may have been in the original clip).

This is a copy of the AHK script:
« Last Edit: July 28, 2012, 07:55:27 AM by IainB; Reason: Script tidied up to enable easier comparison with later comment. » Logged
mouser
First Author
Administrator
*****
Posts: 33,706



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #1 on: February 28, 2012, 07:24:33 AM »

Interesting.

It makes me happy that you like CHS enough to use it despite it not doing everything you need.

Eventually CHS will support saving fully formatted text and you won't have to go through such hoops.

But in the meantime i think i might be able to come up with an easier workaround for you:

You have diagnosed the problem, which is that when you ask CHS to paste the last clip as plaintext, it overwrites the current clipboard. I can try to fix that.
Logged
IainB
Supporting Member
**
Posts: 4,881


Slartibartfarst

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #2 on: February 28, 2012, 11:53:22 AM »

It makes me happy that you like CHS enough to use it despite it not doing everything you need.
 ...
You have diagnosed the problem, which is that when you ask CHS to paste the last clip as plaintext, it overwrites the current clipboard. I can try to fix that.
Oh, thankyou!
I use CHS because it is the best clipboard manager that I have found.
I mentioned elsewhere that I don't regard this as a problem or bug with CHS. It's just something that I personally find a nuisance because of my way of working.
It's not a show-stopper as far as I am concerned.

Ideally, I'd like CHS to save the formatting/RTF or mixed text and image objects too...    smiley  (endearing smile)
Logged
IainB
Supporting Member
**
Posts: 4,881


Slartibartfarst

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #3 on: July 28, 2012, 09:09:34 AM »

Thought I'd better post this as an update/correction.
I had been experiencing some episodic but erratic behaviour (time-delays and failure to complete) in the proper pasting of formatted and unformatted text - where sometimes quite large Clipboard contents were involved - using the above AHK script. It worked OK before.
Since I had not changed the script, I figured that changes from either/both of CHS updates or Win7-64 updates had altered the behind-the-scenes Clipboard process activity/timings.

This was the script from above:
;-------------------------------------------------------------------
UnformattedPaste:                    ; Text–only unformatted paste from ClipBoard
   ClipSaved := ClipboardAll       ; save original clipboard contents
   Clipboard = %Clipboard%      ; Convert to text + remove formatting
   Send ^v                               ; send the Ctrl+v command
   Clipboard := ClipSaved          ; restore the original clipboard contents
   ClipSaved =                          ; clear the variable
Return
;-------------------------------------------------------------------

I managed to fix it all up after reading through:
- and by changing the above script to this:
;-------------------------------------------------------------------
UnformattedPaste:              ; MARK2 Text–only unformatted paste from ClipBoard
   ClipSaved = %ClipBoardAll%   ; save original clipboard contents
   ClipBoard = %ClipBoard%   ; Convert to text + remove formatting
   Send ^v                         ; For best compatibility: SendPlay
   Sleep 50                         ; Don't change clipboard while it is pasted! (Sleep > 0)
   ClipBoard = %ClipSaved%       ; Restore original ClipBoard
   VarSetCapacity(ClipSaved, 0)   ; Free memory
Return
;-------------------------------------------------------------------

The erratic behaviour seems to have completely gone away.

The MARK2 script may be faster (more efficient) because it stores values in variables as expressions:
Quote
Storing values in variables: To store a string or number in a variable, there are two methods: traditional and expression. The traditional method uses the equal sign operator (=) to assign unquoted literal strings or variables enclosed in percent signs.
- and tidier, because it uses arguably good/better practice to clear up and zeroise its ad hoc memory footprint.
However, I would suppose (have no proof) that the "Sleep 50" bit may be what fixed it though, allowing differences in CPU speed and memory speed to run their sequential course without interruption, where larger amounts of data are stored in the Clipboard.
It would be interesting to know exactly what had been going on in the CPU/RAM though.

The new MARK2 script is cribbed from the script posted by the most excellent Lazlo (Posted: July 29th, 2006, 3:20 pm) in the above AHK forum link.
Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.031s | Server load: 0.08 ]