topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 1:22 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: CHS: Share your custom modification scripts here  (Read 11488 times)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
CHS: Share your custom modification scripts here
« on: October 10, 2011, 08:55 PM »
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 [Select]
  1. # check and get commandline args
  2. ($#ARGV >=1) || die "ERROR: first two arguments should be input path and output path (place each one in double quotes)\n";
  3. $infilepath=$ARGV[0];
  4. $outfilepath=$ARGV[1];
  5.  
  6. # open files
  7. open(IN,$infilepath) || die "cannot open input file";
  8. open(OUT,">".$outfilepath) || die "cannot open output file";
  9.  
  10. # write out modified text
  11. while(<IN>)
  12.         {
  13.         # reverse the line
  14.         $outline = reverse($_);
  15.         # now write it out
  16.         print OUT $outline;
  17.         }
  18.  
  19. # close files
  20. close(IN);
  21. 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:
https://www.donation...s/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 10, 2011, 09:01 PM by mouser »

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,544
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: CHS: Share your custom modification scripts here
« Reply #1 on: October 11, 2011, 07:07 AM »
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,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: CHS: Share your custom modification scripts here
« Reply #2 on: October 11, 2011, 07:08 AM »
no, though i suppose i could add such a feature if there was a use for it.

capitalH

  • Participant
  • Joined in 2008
  • *
  • Posts: 71
    • View Profile
    • Donate to Member
Run AHK
« Reply #3 on: October 13, 2011, 08:03 AM »
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 [Select]
  1. if %0%<=1                                       ;only run if two parameters given
  2.         exitapp
  3.        
  4. infile=%1%                              ;infile first paramater
  5. outfile=%2%                             ;outfile second parameter
  6.  
  7. ;read contents of InFile
  8. FileRead, InFileContents, %Infile%
  9.  
  10. SplitPath, OutFile , OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
  11.  
  12. ;delete old ahk file - using append
  13. FileDelete, %OutDir%\%OutNameNoExt%.ahk
  14.  
  15. ;create new ahk file
  16. FileAppend , #SingleInstance force`n`n%inFileContents%`n`n`n`n ~esc::ExitApp, %OutDir%\%OutNameNoExt%.ahk
  17.  
  18. ;copies infile to outfile - otherwise an error will occur (or alternatively if outfile already exist - old stuff will pe pasted)
  19. FileCopy, %InFile%, %OutFile%,1
  20.  
  21. ;run ahk code
  22. run   %OutDir%\%OutNameNoExt%.ahk

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: CHS: Share your custom modification scripts here
« Reply #4 on: October 13, 2011, 08:14 AM »
Very neat  :up:

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,544
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: CHS: Share your custom modification scripts here
« Reply #5 on: October 13, 2011, 10:37 PM »
@capitalH: (Your script.) Yes, rather neat. Thanks. Could be a useful shortcut for testing bits of AHK code.   :Thmbsup:

@mouser:
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?

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, 02:58 AM by IainB, Reason: Corrected the example string \"extract Deming\". »

capitalH

  • Participant
  • Joined in 2008
  • *
  • Posts: 71
    • View Profile
    • Donate to Member
Re: CHS: Share your custom modification scripts here
« Reply #6 on: October 14, 2011, 03: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:
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:
;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
    • View Profile
    • Donate to Member
LBA (Re: CHS: Share your custom modification scripts here)
« Reply #7 on: December 18, 2011, 12:13 AM »
Put a little utility together that displays a pop-up menu of AHK_L scripts to choose from.  

lba-menu-0.8.pngCHS: Share your custom modification scripts here

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 [Select]
  1. ChangeText(InputText)
  2. {
  3.   OutputDebug, % "Before: " . InputText
  4.   Result := Trim(InputText)
  5.   OutputDebug, % "After: " . Result
  6.   Return Result
  7. }

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 22, 2011, 09:16 PM by ewemoa »

cranioscopical

  • Friend of the Site
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,776
    • View Profile
    • Donate to Member
Re: CHS: Share your custom modification scripts here
« Reply #8 on: December 18, 2011, 11:32 AM »
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 ;))
 

cranioscopical

  • Friend of the Site
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,776
    • View Profile
    • Donate to Member
Re: CHS: Share your custom modification scripts here
« Reply #9 on: December 18, 2011, 11:36 AM »
I created a RegEx preset... I will share
And thank you for doing so, and explaining it.