DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: CHS: Share your custom modification scripts here  (Read 14,648 times)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
CHS: Share your custom modification scripts here
« on: October 11, 2011, 01:55 AM »
Building off of the screencast video here, and a recent discussion on using scripts to transform text here, i thought maybe it would make sense to have a thread where people might share their Clipboard Help+Spell scripts and executables for transforming text.

NOTE: You currently need to download the ALPHA RELEASE of CHS 2.09.01 to use these tools.



I'm going to start with this sample perl script that does nothing but reverse the order of characters on each line of text.  This is not useful in and of itself, but it does serve as a skeleton for those who might want to write perl scripts for Clipboard Help+Spell.  This sample script file is included with the new version of CHS (v2.09.01) in the tools folder.  Note that you need to have perl installed and configured on your pc to use perl .pl scripts directly from Clipboard Help+Spell:
Code: (perl)
# check and get commandline args
($#ARGV >=1) || die "ERROR: first two arguments should be input path and output path (place each one in double quotes)\n";
$infilepath=$ARGV[0];
$outfilepath=$ARGV[1];

# open files
open(IN,$infilepath) || die "cannot open input file";
open(OUT,">".$outfilepath) || die "cannot open output file";

# write out modified text
while(<IN>)
	{
	# reverse the line
	$outline = reverse($_);
	# now write it out
	print OUT $outline;
	}

# close files
close(IN);
close(OUT);



Next up is a link where you can download the C++ source code for a C++ tool that does a similar thing -- takes input and output file paths on commandline and performs a text transformation:
http://www.donationcoder.com/Software/Mouser/clipboardhelpandspell/downloads/chs_sampletool.zip

This was built using visual studio 2010, but it's plain ordinary c++ that can be compiled with any c++ compiler.



So, anyone got any to share?
« Last Edit: October 11, 2011, 02:01 AM by mouser »

IainB

  • @Slartibartfarst
  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,544
Re: CHS: Share your custom modification scripts here
« Reply #1 on: October 11, 2011, 12:07 PM »
Is it possible to trigger these scripts to run automatically on the contents of a clip, each time a new clip record is captured?

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: CHS: Share your custom modification scripts here
« Reply #2 on: October 11, 2011, 12:08 PM »
no, though i suppose i could add such a feature if there was a use for it.

capitalH

  • Participant
  • Joined in 2008
  • *
  • Posts: 71
Run AHK
« Reply #3 on: October 13, 2011, 01:03 PM »
Runs current selection as AHK code (i.e. creates tempfile with .ahk extension and runs it)

Requires autohotkey to be installed, and associated with .ahk files

Since users of this will know AHK - I will assume that no further explanation is required.

Code: (autohotkey)
if %0%<=1					;only run if two parameters given
	exitapp
	
infile=%1%				;infile first paramater
outfile=%2%				;outfile second parameter

;read contents of InFile
FileRead, InFileContents, %Infile%

SplitPath, OutFile , OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive

;delete old ahk file - using append
FileDelete, %OutDir%\%OutNameNoExt%.ahk

;create new ahk file
FileAppend , #SingleInstance force`n`n%inFileContents%`n`n`n`n ~esc::ExitApp, %OutDir%\%OutNameNoExt%.ahk

;copies infile to outfile - otherwise an error will occur (or alternatively if outfile already exist - old stuff will pe pasted)
FileCopy, %InFile%, %OutFile%,1

;run ahk code
run   %OutDir%\%OutNameNoExt%.ahk

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: CHS: Share your custom modification scripts here
« Reply #4 on: October 13, 2011, 01:14 PM »
Very neat  :up:

IainB

  • @Slartibartfarst
  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,544
Re: CHS: Share your custom modification scripts here
« Reply #5 on: October 14, 2011, 03:37 AM »
@capitalH: (Your script.) Yes, rather neat. Thanks. Could be a useful shortcut for testing bits of AHK code.   :Thmbsup:

@mouser:
Quote
IainB: Is it possible to trigger these scripts to run automatically on the contents of a clip, each time a new clip record is captured?
Quote
mouser: no, though i suppose i could add such a feature if there was a use for it.

Well, if the feature existed, this is an example of a repetitive task that I would use it for:
What I would like to be able to do is select (enable) a script that automatically inserts a string of text of my choosing into each sucessive clip taken, until I disable it. This would be an optional "run until" model - it differs to the current model which is (if I have it aright) where you manually select a script to "run once" only.

Thus, if I were (say) gathering clips on the subject of Deming, then I could use the string "extract Deming", so that every clip could have the string "extract Deming" appended to it - whether it originally contained the word or not. Then, I could subsequently use an SQL filter to collect all the occurrences of clips with "extract Deming" into a Virtual Folder. Once they were in the VF, I could then do whatever I wanted with them - e.g., (say) concatenate them as a set of contiguous notes, for pasting elsewhere.

Does that make sense?
« Last Edit: October 14, 2011, 07:58 AM by IainB »

capitalH

  • Participant
  • Joined in 2008
  • *
  • Posts: 71
Re: CHS: Share your custom modification scripts here
« Reply #6 on: October 14, 2011, 08:32 AM »
I created a RegEx preset - and since I spent a long time trying to figure out how to do it (RegEx is something I still struggle with), I though I will share

What I want to do: create presets that comments code out (and next up uncomments it as well) for AHK, Latex and Python - however since only the comment character differs the implementation follow naturally from the first (AHK given in example):
for example, to change:
Code
Line 1
 Line 2 ;space
	Line 3 ;tab
  Line 4 ;2space
		Line 5 ;2tab
;  Line 6 ;already commented
;		Line 7 ;already commented
	 	;Line 8 ;already commented, with indent
to:
Code
;Line 1
; Line 2 ;space
;	Line 3 ;tab
;  Line 4 ;2space
;		Line 5 ;2tab
;  Line 6 ;already commented
;		Line 7 ;already commented
;	 	;Line 8 ;already commented, with indent
(off topic - you might not want to double comment Line 8 - but this is the way I prefer it )

you can use
Add Stuff|Add to Lines|Prefix : ";" (obviously without the quotes

Find and replace - enable RegEx
Find "^[;;]" (no quotes)
Replace "" (empty string - no quotes)

The RegEx prevents Line 6 and 7 from being double commented (and subsequently upon running this twice or more - maybe with a wider selection - prevents endless comment characters)

To remove
Trimming and Wrapping|Strip Leading Stuff|";"

Mouser - is there somehow that the internal stuff (i.e. presets not using custom tools) like this can be packaged as part of an add-on for CHS? Or packaged with CHS and then have a preset manager where you can delete/disable/enable the unneeded ones. I am more than willing to share my files (stuff like paragraph stripping - for copying from Adobe reader etc - but nothing fancy).

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • Plugin Coding Medal
    • Participated in NANY Challenge Three Times
LBA (Re: CHS: Share your custom modification scripts here)
« Reply #7 on: December 18, 2011, 06:13 AM »
Put a little utility together that displays a pop-up menu of AHK_L scripts to choose from.  

lba-menu-0.8.png

Currently, each menu item above the separator corresponds to a single AHK_L script.  Choosing the menu item should lead to the execution of the corresponding script.

Below is source to the current script for trimming:

Code: (autohotkey)
ChangeText(InputText)
{
  OutputDebug, % "Before: " . InputText
  Result := Trim(InputText)
  OutputDebug, % "After: " . Result
  Return Result
}

To make one's own scripts, basically:

  • Make a new file with extension .ahk in the scripts folder
  • In the .ahk file, define a function named 'ChangeText' - it should have a single parameter
  • In the body of the function, transform the text passed in as desired and use Return to communicate the result to CHS

Installation instructions should be in the README.txt within the archive, but it's pretty much the same as the other custom modification scripts.

MD5: 90eeccc94446f2e8303d82de60af1865
LBA

Note: no compilation of scripts is necessary thanks to AutoHotkey.dll and AHK_L.
« Last Edit: December 23, 2011, 03:16 AM by ewemoa »

cranioscopical

  • Friend of the Site
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,776
    • Cody Award
    • Official Forum Clown
    • rotten turkey sandwich - Rotten Turkey Sandwich
Re: CHS: Share your custom modification scripts here
« Reply #8 on: December 18, 2011, 05:32 PM »
no, though i suppose i could add such a feature if there was a use for it.
I could see a use for that if you felt like adding it to your list (probably after accessing other clipboard formats ;))

Chris

cranioscopical

  • Friend of the Site
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,776
    • Cody Award
    • Official Forum Clown
    • rotten turkey sandwich - Rotten Turkey Sandwich
Re: CHS: Share your custom modification scripts here
« Reply #9 on: December 18, 2011, 05:36 PM »
I created a RegEx preset... I will share
And thank you for doing so, and explaining it.
Chris

Original address: https://www.donationcoder.com/forum/index.php?topic=28312.0