Here´s a slightly improved version of a previous script.
Now the marking of the clipboard contents to be quoted is configurable.
BTW, @Toralf, Chris:
WinActive("WinTitle") is case sensitive whereas StringGetPos
and InStr(ActiveTitle,WinTitle) are not.
Now a version 1.1
; Insert Clipboard Contents as External Quotes into an Email Editor
; 2005-06-14,2005-07-03
; OS=WinXP, AHK=1.0.34, Author=HJS (Hajos)
; This program transforms the current clipboard contents to linewise
; quoted paragraphs and inserts it into the current window -
; provided the window title contains a specified string.
; Long paragraphs are broken to specified line length.
; Intended for use in email editors such as TB
; Improved handling of script´s hotkey (thanks Andreas Borutta)
#SingleInstance force
#UseHook
SetTitleMatchMode, 2
xq_ScriptName = InsertExternalQuote_1_1
Gosub, xq_Init
Gosub, xq_GuiBuild
xq_always := ( xq_titletext = "" )
Gosub, xq_makehotkey
; Gosub, xq_conf
Return
xq_Init:
Menu, Tray, NoStandard
Menu, Tray, Add, Config, xq_conf
Menu, Tray, Add, Exit, xq_Exit
Menu, Tray, Add, ,
Menu, Tray, Default, Config
AutoTrim, Off
IniRead, xq_hk, %xq_Scriptname%.ini, Config, Hotkey, ^+v
IniRead, xq_quotemark, %xq_Scriptname%.ini, Config, Quotemark, |"A_Space"
IniRead, xq_ClpOnly, %xq_Scriptname%.ini, Config, ClipOnly, 0
IniRead, xq_charsperline, %xq_Scriptname%.ini, Config, CharsPerLine, 68
IniRead, xq_titletext, %xq_Scriptname%.ini, Config, TitleText, Verfassen:
StringReplace, xq_quotemark, xq_quotemark, "A_Space",%A_Space%, ALL
Return
xq_GuiBuild:
xq_Insert := not xq_ClpOnly
Gui, Add, Text, Section xm , Mark each Clipboard line by
Gui, Add, Edit, ys w40 vxq_quotemark, %xq_quotemark%
Gui, Add, Text, Section x+20 ys-5 , by Hajos
Gui, Add, Text, Section xm , Hotkey:
Gui, Add, Hotkey, ys w200 vxq_hk , %xq_hk%
Gui, Add, Radio, Section xm vxq_Insert Checked%xq_Insert%, Insert Clipboard contents in current window
Gui, Add, Radio, Section xm vxq_ClpOnly Checked%xq_ClpOnly%, Only lineBreak and marking of Clipboard contents
Gui, Add, Text, Section xm , Characters per line: `n (0 = no line Break)
gui, Add, Edit, ys w30 Number vxq_charsperline, %xq_charsperline%
Gui, Add, Text, ys , ("1" yields a word List)
Gui, Add, Text, Section xm y+20 , Text in current window´s title:`n(blank: active in any window)
gui, Add, Edit, ys w100 vxq_titletext, %xq_titletext%
Gui, Add, Button, Default xm w70, OK
Gui, Add, Button, xp+180 yp wp, Cancel
GuiControl, Focus, OK
Return
; ----------------------------------------
xq_conf:
; user hotkey off so that it can be changed and
; restored by user during configuration
If ( xq_oldhk != "" )
Hotkey, %xq_oldhk%, Off
gui,Show, ,%xq_Scriptname%
Return
ButtonCancel:
GuiClose:
GuiEscape:
gui, Cancel
If ( xq_oldhk != "" )
Hotkey, %xq_oldhk%, On
Return
ButtonOK:
Gui, Submit
xq_always := ( xq_titletext = "" )
Gosub, xq_makehotkey
IniWrite, %xq_hk%, %xq_Scriptname%.ini, Config, Hotkey
IniWrite, %xq_ClpOnly%, %xq_Scriptname%.ini, Config, ClipOnly
IniWrite, %xq_charsperline%, %xq_Scriptname%.ini, Config, CharsPerLine
IniWrite, %xq_titletext%, %xq_Scriptname%.ini, Config, TitleText
StringReplace, xq_quotemark2, xq_quotemark,%A_Space%,"A_Space", ALL
IniWrite, %xq_quotemark2%,%xq_Scriptname%.ini, Config, Quotemark
Return
Exit:
xq_Exit:
ExitApp
; ----------------------------------------
xq_makehotkey: ; install user hotkey
If ( xq_hk != "" ) ; variable xq_hk contains the user hotkey
{
If ( xq_oldhk != xq_hk )
Hotkey, %xq_hk%, xq_InsertQuotedClipBd
; store current hotkey in xq_oldhk for next call of xq_conf
xq_oldhk := xq_hk
Hotkey, %xq_oldhk%, On
}
Return
; ----------------------------------------
xq_InsertQuotedClipBd:
WinGetActiveTitle, Active_title
If ( xq_always or Instr(Active_title, xq_titletext) )
{
xq_qmlen := strlen( xq_quotemark )
xq_a:=Clipboard
If ( xq_charsperline > 0 )
xq_BreakLines( xq_charsperline - xq_qmlen + 1 )
Else ; no line break of clipboard contents
{
StringReplace, xq_b, xq_a, `n,`n%xq_quotemark%, A
StringRight, xq_c, xq_b, xq_qmlen
If xq_c =%xq_quotemark%
StringTrimRight, xq_b, xq_b, xq_qmlen
Clipboard=%xq_quotemark%%xq_b%
}
If not xq_ClpOnly
{
Send, ^v
Clipboard=%xq_a%
}
}
Else ; special function of user hotkey not applicable
Send, %xq_hk%
Return
xq_BreakLines(n)
{
local l, p
xq_b =
Loop, Parse, Clipboard, `n, `r
{
xq_c := A_LoopField ; for every line ...
Loop
{
l:=StrLen(xq_c)
If ( l < n )
Break
; search for a point to cut the line
StringGetPos, p, xq_c,%A_Space%, R1, l - n
If ( ErrorLevel )
{
StringGetPos, p, xq_c,%A_Space%, L1
If ( ErrorLevel )
Break
}
StringMid, xq_d, xq_c, 1, p
StringTrimLeft, xq_c, xq_c, p +1
xq_b=%xq_b%%xq_quotemark%%xq_d%`r`n
}
xq_b=%xq_b%%xq_quotemark%%xq_c%`r`n ; add quotemark and line
}
StringRight, xq_c, xq_b, xq_qmlen + 2
If xq_c =%xq_quotemark%`r`n
StringTrimRight, xq_b, xq_b, xq_qmlen + 2
Clipboard=%xq_b%
}
Changes:
Changing the script´s hotkey was buggy; hopefully fixed (thanks A. Borutta)
Fixed: handling of last line in case the quote mark is longer than 2 chars
Greetings, Hajos