 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Andreas Borutta
Joined: 23 Jan 2005 Posts: 47
|
Posted: Sun Jun 05, 2005 8:08 am Post subject: [Search] Script for email appl.: "Paste as external quo |
|
|
Since I use thunderbird as my email application, I miss one very important function:
Paste a text as an external quote.
An external quote uses the quoteinitial "|" not the ">" (which mark the writing of the sender of the previous mail).
Example:
Lets assume I like to paste a text from the page
http://autohotkey.com/docs/Tutorial.htm
The result should look like:
| Code: | Hi,
> Do I need a special tool to edit a script?
No. See the excerpt from http://autohotkey.com/docs/Tutorial.htm below:
| Creating a script
|
| Each script is a plain text file containing commands to be executed
| by the program (AutoHotkey.exe). A script may also contain hotkeys
| and hotstrings, or even consist entirely of them.
| ...
Regards, Andreas
|
May be one of you programmers likes the idea and wants to write a script for this function.
If it works, I will tell others from this solution in my tip-collection around thunderbird (see below) of course with credits to the author of the script
I know several thunderbird users who long for this function. _________________ Andreas
http://borumat.de/autohotkey-autotexte-und-makros-tipps (german)
http://borumat.de/thunderbird-email-tipps (german)
http://borumat.de/firefox-browser-tipps (german) |
|
| Back to top |
|
 |
Hajos
Joined: 04 Jun 2005 Posts: 17 Location: Göttingen
|
Posted: Sun Jun 05, 2005 4:19 pm Post subject: |
|
|
I like the idea.
You might try the following lines: | Code: |
$^+v::
WinGetTitle, active_title, A
; Thunderbird
StringGetPos, thbd_pos, active_title, Verfassen: ; German version of TB
If ( thbd_pos = 0 )
{
thbd_a:=Clipboard
StringReplace, thbd_b, thbd_a, `n,`n|%A_Space%, A
StringRight, thbd_c, thbd_b,2
If thbd_c =|%A_Space%
StringTrimRight, thbd_b, thbd_b,2
Clipboard=|%A_Space%%thbd_b%
Send, ^v
Clipboard=%thbd_a%
}
Else
Send, ^+v
Return
|
greetings |
|
| Back to top |
|
 |
Guest
|
Posted: Sun Jun 05, 2005 5:36 pm Post subject: |
|
|
| Hajos wrote: | | I like the idea. [Script] |
Fine
Thank you for your willingness.
Well, I do not understand precisely what the code do, but it seems that it tries to search for the string "thunderbird" in the title of windows, doesn't it.
I eliminated this string as well in thundbird as I did in firefox or openoffice, because the legibility of file names is better without it.
I would be just happy if the external quote will fill the clipboard.
This will even make the script more flexible and one could use it in what ever emailclient not only in thunderbird.
May I ask you to change the script to make it independent?
Important is the possibility for the user to be able to configure the maximum number of characters for each line.
It is also important, that the linebreak mechanism respects the paragraphs, when the selected text is from a HTML page.
Please let me know, if you need more details of the script idea.  |
|
| Back to top |
|
 |
Hajos
Joined: 04 Jun 2005 Posts: 17 Location: Göttingen
|
Posted: Tue Jun 07, 2005 8:08 pm Post subject: |
|
|
The code of second post above changes the behaviour of the Shift-Ctrl-V key
in TB editor only, such that the current clipboard contents are marked with "| " at the beginning of each line.
| Quote: |
... it seems that it tries to search for the string "thunderbird" in the title of windows, doesn't it.
|
No. It looks for the string "Verfassen:" contained in the title of German TB editor
I built a little Gui around the hotkey routine making it configurable.
| Code: |
; Insert Clipboard Contents as External Quotes into an Email Editor
; 2005-06-07
; 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 a specified line length.
; It is intended for use in email editors as e.g. TB
#singleinstance force
#UseHook
xq_ScriptName = InsertExternalQuote
Menu, Tray, NoStandard
Menu, Tray, Add, Config, xq_Conf
Menu, Tray, Add, Exit, xq_Exit
Menu, Tray, Add, ,
Menu, Tray, Default, Config
; Default values
xq_hk = ^+v
xq_ClpOnly=0
xq_charsperline = 64
xq_titletext = Verfassen: ; string in window title of German version TB editor
IfExist, %xq_Scriptname%.ini
{
IniRead, xq_hk, %xq_Scriptname%.ini, Config, Hotkey, ^+v
IniRead, xq_ClpOnly, %xq_Scriptname%.ini, Config, ClipOnly, 0
IniRead, xq_charsperline, %xq_Scriptname%.ini, Config, CharsPerLine, 0
IniRead, xq_titletext, %xq_Scriptname%.ini, Config, TitleText, Verfassen:
}
Gosub, xq_GuiBuild
gui, show, ,%xq_Scriptname%
Return
xq_GuiBuild:
xq_Insert := not xq_ClpOnly
Gui, Add, Text, Section xm , Mark external quotes by "| " 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 quoted current Clipboard contents
Gui, Add, Radio, Section xm vxq_ClpOnly Checked%xq_ClpOnly%, Only mark current 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, Section xm y+20 , Text in editor window´s title:
gui, Add, Edit, ys w105 vxq_titletext, %xq_titletext%
Gui, Add, Button, Default xm w70, OK
Return
ButtonOK:
GuiClose:
; GuiEscape:
Gui, Submit
Gosub, xq_makehk
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
Return
Exit:
xq_Exit:
ExitApp
xq_conf:
gui,show, ,%xq_Scriptname%
Return
; ----------------------------------------
xq_makehk: ; install hotkey
IfNotEqual, xq_oldhk,
Hotkey, %xq_oldhk%,Off
IfNotEqual, xq_hk,
{
Hotkey, %xq_hk%, xq_InsertQuoted
Hotkey, %xq_hk%, On
}
xq_oldhk := xq_hk
Return
xq_InsertQuoted:
WinGetTitle, active_title, A
If xq_titletext =
xq_pos = 0
Else
StringGetPos, xq_pos, active_title, %xq_titletext%
If ( xq_pos >= 0 )
{
xq_a:=Clipboard
If ( xq_charsperline > 0 )
xq_BreakLines( xq_charsperline - 1 )
Else
{
StringReplace, xq_b, xq_a, `n,`n|%A_Space%, A
StringRight, xq_c, xq_b,2
If xq_c =|%A_Space%
StringTrimRight, xq_b, xq_b,2
Clipboard=|%A_Space%%xq_b%
}
If not xq_ClpOnly
{
Send, ^v
Clipboard=%xq_a%
}
}
Else
Send, %xq_hk%
Return
xq_BreakLines(n)
{
local l, p
xq_b =
Loop, Parse, Clipboard, `n, `r
{
xq_c := A_LoopField
Loop
{
l:=StrLen(xq_c)
If ( l < n )
Break
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%|%A_Space%%xq_d%`r`n
}
xq_b=%xq_b%|%A_Space%%xq_c%`r`n
}
StringRight, xq_c, xq_b,4
If xq_c =|%A_Space%`r`n
StringTrimRight, xq_b, xq_b,4
Clipboard=%xq_b%
}
|
| Quote: |
It is also important, that the linebreak mechanism respects the paragraphs, when the selected text is from a HTML page.
|
Please explain or give an example.
Hajos |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Wed Jun 08, 2005 11:56 am Post subject: |
|
|
Hi Hajos,
nice script, and well structured.
I read it through and have some comments.
1) you could shorten the following section:
| Code: | ;Default values
xq_hk = ^+v
xq_ClpOnly=0
xq_charsperline = 64
xq_titletext = Verfassen: ; string in window title of German version TB editor
IfExist, %xq_Scriptname%.ini
{
IniRead, xq_hk, %xq_Scriptname%.ini, Config, Hotkey, ^+v
IniRead, xq_ClpOnly, %xq_Scriptname%.ini, Config, ClipOnly, 0
IniRead, xq_charsperline, %xq_Scriptname%.ini, Config, CharsPerLine, 0
IniRead, xq_titletext, %xq_Scriptname%.ini, Config, TitleText, Verfassen:
}
| to this | Code: | ;Default values
IniRead, xq_hk, %xq_Scriptname%.ini, Config, Hotkey, ^+v
IniRead, xq_ClpOnly, %xq_Scriptname%.ini, Config, ClipOnly, 0
IniRead, xq_charsperline, %xq_Scriptname%.ini, Config, CharsPerLine, 64
IniRead, xq_titletext, %xq_Scriptname%.ini, Config, TitleText, Verfassen:
|
2) instead of
| Code: | WinGetTitle, active_title, A
If xq_titletext =
xq_pos = 0
Else
StringGetPos, xq_pos, active_title, %xq_titletext%
If ( xq_pos >= 0 )
{
[...]
} | you could use | Code: | IfWinActive, %xq_titletext%
{
[...]
} |
_________________ Ciao
toralf  |
|
| Back to top |
|
 |
Hajos
Joined: 04 Jun 2005 Posts: 17 Location: Göttingen
|
Posted: Thu Jun 09, 2005 1:05 pm Post subject: |
|
|
Hi Toralf,
I agree with your first point but not with the second one.
Though not explicitly stated in my previous post, an empty %xq_titletext% is meant to allow the hotkey to work in all windows.
"IfWinActive, %xq_titletext%" doesn´t do it.
But I´d like to see a more elegant way to reach this objective.
Hajos |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Thu Jun 09, 2005 3:27 pm Post subject: |
|
|
Ok, I hope I got it now. | Code: | If xq_titletext =
doit := True
Else IfWinActive, %xq_titletext%
doit := True
Else
doit := False
If doit
{
[...]
} | *not tested*
or like this
| Code: | doesexist := False
IfWinActive, %xq_titletext%
doesexist := True
If (xq_titletext <> "" or doesexist)
{
[...]
} | *not tested* _________________ Ciao
toralf  |
|
| Back to top |
|
 |
Hajos
Joined: 04 Jun 2005 Posts: 17 Location: Göttingen
|
Posted: Wed Jun 15, 2005 9:26 am Post subject: |
|
|
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
| Code: | ; 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
Last edited by Hajos on Sun Jul 03, 2005 3:03 pm; edited 1 time in total |
|
| Back to top |
|
 |
Melaneres Guest
|
Posted: Wed Jun 15, 2005 10:28 pm Post subject: |
|
|
Hajos:
Thanks, I like this script very much.
Is there a way to hide the GUI at the start and only show it with Config?
Melaneres |
|
| Back to top |
|
 |
Hajos
Joined: 04 Jun 2005 Posts: 17 Location: Göttingen
|
Posted: Mon Jun 20, 2005 10:46 am Post subject: |
|
|
Hello, Melaneres,
| Quote: | | Is there a way to hide the GUI at the start and only show it with Config? | Yes. Replace line #18 | Code: | gui, show, ,%xq_Scriptname%
| by | Code: | xq_always := ( xq_titletext = "" )
Gosub, xq_makehk | to activate the hotkey immediately
Hajos |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Jun 20, 2005 11:28 am Post subject: |
|
|
Thank you, Hajos, it's perfect!
(I tried "gui, hide" - but had to realize that I don't have a clue...)
Melaneres |
|
| Back to top |
|
 |
Hajos
Joined: 04 Jun 2005 Posts: 17 Location: Göttingen
|
Posted: Sun Jul 03, 2005 3:09 pm Post subject: |
|
|
Seems, hardly anything is ever finished.
Found some bugs (thnx A. Borutta)
Edited the last but three post
Hajos |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|