Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

PhraseOMatic common phrase insertion utility


  • Please log in to reply
9 replies to this topic
DaTex
  • Members
  • 5 posts
  • Last active: Jul 14 2014 03:16 AM
  • Joined: 21 Nov 2006
PhraseOMatic

I wrote PhraseOMatic because I couldn't find an existing AHK script that did the same thing.

Often we have our own collection of terms and phrases that we type over and over, whether it is a company or department name, a URL we reference, or perhaps some quotes we like to use.

PhraseOMatic.ahk is a utility that resides in the System Tray and loads your common phrases from a text file (PhraseOMatic.txt) that is kept in the same folder as the script. The current hotkey I use is F6, which activates a pop-up menu at the mouse location with the list of phrases. You can use either the cursor keys + Enter or a mouse-click to select the phrase, which is then inserted into the window you were in (document, email, etc.).

A sample PhraseOMatic.txt file is shown here:
MenuTitle:*-= Select Phrase to Insert from the file PhraseOMatic.txt =-*
ToolTip:PhraseOMatic (F6)
Shell32.dll Icon:47
<---- Add / Edit Text Items Below This Line ---->
[Universities]
The University of Arizona
Oklahoma State University
Harvard University
Mississippi State University
Ohio State University
[/] Comment at the end of a Submenu block

[-] Comment on a Separator Line
Four score and seven years ago
Ask not what your country can do for you
Once upon a time

[Titles]
Chief Executive Officer (CEO)
Vice-President of Legal Affairs
Vice-President of Finance
Director of Research and Engineering
Director of Marketing
[/]

A zip file of the utility may be found at AutoHotKey.net here (PhraseOMatic.ahk, Readme.txt, PhraseOMatic.txt file). Feedback is appreciated.

DaTex

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
Interesting use of the menu, nice a simple. The only "problem"
I see is if one would have many many phrases (as I have)

That is why I modified Boskoops "Listbox with incremental search"
<!-- m -->http://www.autohotke.../topic2534.html<!-- m -->
(which has the added bonus of allowing you to search through a large collection and the phrase can have linebreaks as well)

I think Boskoops' script is one of the more underestimated scripts here on the forum, there doesn't seem to be much interest in it and it complements
AHKs "AutoCorrect" feature so well IMHO.

But thanks for sharing your script!

DaTex
  • Members
  • 5 posts
  • Last active: Jul 14 2014 03:16 AM
  • Joined: 21 Nov 2006
Updates to PhraseOMatic

I streamlined the code somewhat, and I simplified the syntax used in the data file PhraseOMatic.txt. The sample data file is shown here:
MenuTitle:*-= Select Phrase to Insert from the file PhraseOMatic.txt =-*
ToolTip:PhraseOMatic (F6)
Shell32.dll Icon:47
Certain first characters on a line have special meaning:
/ Ends a Submenu Block
- Inserts a Separator Line
; Comment (non-displaying)
> Comment (displays but does nothing if clicked)
<---- Add / Edit Text Items Below This Line ---->
[Universities]
The University of Arizona
Oklahoma State University
Harvard University
Mississippi State University
Ohio State University
/ Comment at the end of a Submenu block

; Comment on a line by itself

- Comment on a Separator Line
Four score and seven years ago
Ask not what your country can do for you
Once upon a time

[Titles]
> Company Titles
Chief Executive Officer (CEO)
Vice-President of Legal Affairs
Vice-President of Finance
Director of Research and Engineering
Director of Marketing
/

The script code zip file is still available here

DaTex

rogerrabbitthefirst
  • Members
  • 6 posts
  • Last active: Oct 13 2019 08:13 PM
  • Joined: 11 Jan 2014

Hi,
I love this script.

The one modifiction I'd like to make to suit my use of the script is to not have a space at the end of the inserted text. Can anyone assist with this please?
I have tried deleting %A_Space% at the end of the input line (penultimate line), adding {Backspace} at the end of that line, deleting {Raw} and adding {Backspace} at the end of the line, but none of these worked. I'm not an advanced user (can't do programming etc), so have run out of ideas. I'd be very grateful for suggestions, if anyone has any.

The original script is as follows, as it is not on this page:
 

; PhraseOMatic - by DaTex
; This script displays a popup menu of text to insert into the
; current application window at the cursor position
; The user-editable text file also contains program settings such as
; the Menu title, the Windows Tray Icon, and the ToolTip

SetBatchLines, 10ms
#SingleInstance
#Persistent
#WinActivateForce
#NoEnv

;_____ Defaults _____
InHeader=1
InSubmenu=0
TheCatName=
CurrentMenu=PhraseMenu
ThisTitle = *-= Select Phrase to Insert from PhraseOMatic.txt =-*
ThisToolTip = PhraseOMatic (F6)
ThisIcon = 44

;_____ Load file into Popup Menu____________
IfExist, %A_ScriptDir%\PhraseOMatic.txt
{
Loop, Read, %A_ScriptDir%\PhraseOMatic.txt
{
If InHeader
{
If RegExMatch(A_LoopReadLine, "^MenuTitle:(.+)", menutitle)
ThisTitle = %menutitle1%
Else If RegExMatch(A_LoopReadLine, "^ToolTip:(.+)", pom_tooltip)
ThisToolTip = %pom_tooltip1%
Else If RegExMatch(A_LoopReadLine, "^Shell32.dll Icon:(.+)", pom_icon)
ThisIcon = %pom_icon1%
Else If RegExMatch(A_LoopReadLine, "^<----")
{
;Process Header Data and Exit Header Code
InHeader = 0
Menu, %CurrentMenu%, Add, %ThisTitle%, MenuDummy
Menu, %CurrentMenu%, Add ;Separator between title and phrases
Menu, Tray, Tip, %ThisToolTip%
Menu, Tray, Icon, Shell32.dll, %ThisIcon%
}
Continue
}
If RegExMatch(A_LoopReadLine, "^-")
{
Menu, %CurrentMenu%, Add
} Else If RegExMatch(A_LoopReadLine,"^;")
{
;Do nothing - comment line
} Else If RegExMatch(A_LoopReadLine,"^/")
{
CurrentMenu=PhraseMenu
Menu, %CurrentMenu%, Add, %TheCatName%, :%TheCatName%
InSubmenu=0
} Else If RegExMatch(A_LoopReadLine,"^>(.*)", comment)
{
;Non-selectable Menu item (visible comment)
StringReplace, phrase, comment1, &, &&, All
Menu, %CurrentMenu%, Add, %phrase%, MenuDummy
} Else If RegExMatch(A_LoopReadLine,"^\[(.+)\]",catname)
{
; Category Name is saved as TheCatName since CatName1 is overwritten
StringReplace, TheCatName, catname1, &, &&, All
CurrentMenu=%TheCatName%
InSubmenu=1
} Else If A_LoopReadLine ; not blank
{
StringReplace, phrase, A_LoopReadLine, &, &&, All
Menu, %CurrentMenu%, Add, %phrase%, MenuClick
}
}
} Else
MsgBox, 16, PhraseOMatic, Cannot find PhraseOMatic.txt
Menu, tray, add ; Creates a separator line.
SplitPath, A_ScriptName,,,, f_FileName
Shortcut = %A_Startup%\Shortcut to %f_FileName%.lnk
Menu, tray, add, Create Shortcut in Startup Folder, MenuCreateShortcut
IfExist %Shortcut%
Menu, tray, Disable, Create Shortcut in Startup Folder
Menu, tray, add, Edit Phrases, MenuNotepad
Menu, tray, Default, Edit Phrases
Menu, tray, add, Path: %A_ScriptFullPath%, MenuGoPath
Return

;_____Hotkey and Label Section_____
~F6::
Menu, PhraseMenu, Show
Return

MenuCreateShortcut:
FileCreateShortcut, %A_ScriptFullPath%, %Shortcut%
Reload
Return

MenuNotepad:
RunWait, Notepad.exe %A_ScriptDir%\PhraseOMatic.txt
Reload
Return

MenuGoPath:
Run, Explorer.exe %A_ScriptDir%,,Max
Return

MenuDummy:
Return

MenuClick:
WinActivate
; Replace double ampersand (&&) with single again
StringReplace, phrase, A_ThisMenuItem, &&, &, All
Loop, Parse, phrase, %A_Space%
SendInput, {Raw}%A_LoopField%%A_Space%
Return

Thank you.

Roger



Jack Dunning
  • Members
  • 217 posts
  • Last active: Nov 11 2015 08:40 PM
  • Joined: 08 Apr 2013

Perhaps this is too late, but I've just started looking at this script for reviewing in my column. All that's needed to remove the last space is to backspace.

;this is only the last piece of the script

MenuClick:
WinActivate
; Replace double ampersand (&&) with single again
StringReplace, phrase, A_ThisMenuItem, &&, &, All
Loop, Parse, phrase, %A_Space%
SendInput, {Raw}%A_LoopField%%A_Space%
SendInput, {bs}
Return

Add the SendInput, {bs} line after the first SendInput line. This is probably the easiest way to remove the last space.


I currently do a regular blog for AutoHotkey beginners and have posted a number of AutoHotkey help pages at ComputorEdge.com. As I learn, I pass it on.

 

AutoHotkey scripts and apps for beginners and more ideas.


DaTex
  • Members
  • 5 posts
  • Last active: Jul 14 2014 03:16 AM
  • Joined: 21 Nov 2006

Jack et al, I haven't updated this forum topic in a long time, but I recently did make the change to have the space at the end of the paste operation be optional, I added a new setting in the header to keep or remove the space. That way it is dependent upon the phrase file setting (default is to include the space character). I did this because I used PhraseOMatic to insert titles into OneNote pages, and the space character was useless. But in my "normal" phrase files, i want the space character. Look for an updated post with the corrected code soon.



Jack Dunning
  • Members
  • 217 posts
  • Last active: Nov 11 2015 08:40 PM
  • Joined: 08 Apr 2013

I wrote an article on PhraseOMatic and the most recent version (which I received from DaTex) is posted at the ComputorEdge Dropbox site.


I currently do a regular blog for AutoHotkey beginners and have posted a number of AutoHotkey help pages at ComputorEdge.com. As I learn, I pass it on.

 

AutoHotkey scripts and apps for beginners and more ideas.


tdavid
  • Members
  • 1 posts
  • Last active: Nov 03 2014 09:51 AM
  • Joined: 02 Nov 2014

Hi DaTex,

 

First of all, congrats on the script. It's nice and simple. Great for having ready-to-use phrases anywhere, just what I was looking for. My only question/request is: is there a way to set a width limit on the menu and submenues and if a phrase is too long, do a word wrap?

 

I know about the "ParaPhrase" feature, which is not that useful in my case, because I have many phrases that differ only slightly and I wouldn't be able to assign each of them a unique "ParaPhrase" that I could actually remember which phrase it refers to.

 

Thank you

David



rogerrabbitthefirst
  • Members
  • 6 posts
  • Last active: Oct 13 2019 08:13 PM
  • Joined: 11 Jan 2014

Hi DaTex/Jack,

 

Just seen the updated information (I'd given up checking) regarding removing the extra space at the end of the paste. Many thanks! Great script!

 

Roger



bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011

Is this the latest version?:

; PhraseOMatic - by DaTex
; This script displays a popup menu of text to insert into the
; current application window at the cursor position
; The user-editable text file also contains program settings such as
; the Menu title, the Windows Tray Icon, and the ToolTip
; See http://www.autohotkey.net/~DaTex/PhraseOMatic/
; for changelog and feature description

SetBatchLines, 10ms 
#SingleInstance force
#Persistent
#WinActivateForce
#NoEnv
HasRegistry=1 ;Presume the registry keys exist
RegRead, PhraseFile, HKEY_CURRENT_USER, Software\PhraseOMatic
IfEqual, Errorlevel, 1
{
	HasRegistry=0
	PhraseFile=%A_ScriptDir%\PhraseOMatic.txt
}
SplitPath, PhraseFile,,f_PhrasePath

;_____ Defaults _____
InHeader=1
InSubmenu=0
TheCatName=
CurrentMenu=PhraseMenu
ThisTitle = *-= {Click} or {Enter} inserts, with {Shift} -> clipboard =-*
ThisToolTip = PhraseOMatic v1.1.0 (F6)
ThisIcon = 47

;_____ Load file into Popup Menu____________
IfExist, %PhraseFile%
{
	Loop, Read, %PhraseFile%
	{
		If InHeader
		{
			If RegExMatch(A_LoopReadLine, "^;MenuTitle:(.+)", menutitle)
				ThisTitle = %menutitle1%
			Else If RegExMatch(A_LoopReadLine, "^;ToolTip:(.+)", pom_tooltip)
				ThisToolTip = %pom_tooltip1%
			Else If RegExMatch(A_LoopReadLine, "^;Shell32.dll Icon:(.+)", pom_icon)
				ThisIcon = %pom_icon1%
			Else If RegExMatch(A_LoopReadLine, "^;<----")
			{ ;Process Header Data and Exit Header Code
				InHeader = 0
				Menu, %CurrentMenu%, Add, %ThisTitle%, MenuDummy
				Menu, %CurrentMenu%, Add ;Separator between title and phrases
				Menu, Tray, Tip, %ThisToolTip%
				Menu, Tray, Icon, Shell32.dll, %ThisIcon%
				Continue
			}
			Else If RegExMatch(A_LoopReadLine,"^;")
				Continue
			Else If A_LoopReadLine ; not blank
			{ ;Process Header Data, Exit Header, and fall through to parse line
				InHeader = 0
				Menu, %CurrentMenu%, Add, %ThisTitle%, MenuDummy
				Menu, %CurrentMenu%, Add ;Separator between title and phrases
				Menu, Tray, Tip, %ThisToolTip%
				Menu, Tray, Icon, Shell32.dll, %ThisIcon%
			}
		}
		If RegExMatch(A_LoopReadLine, "^-")
		{
			Menu, %CurrentMenu%, Add
		} Else If RegExMatch(A_LoopReadLine,"^;")
		{ ;Do nothing - comment line
		} Else If RegExMatch(A_LoopReadLine,"^/")
		{
			CurrentMenu=PhraseMenu
			Menu, %CurrentMenu%, Add, %TheCatName%, :%TheCatName%
			InSubmenu=0
		} Else If RegExMatch(A_LoopReadLine,"^>(.*)", comment)
		{ ;Non-selectable Menu item (visible comment)
			StringReplace, phrase, comment1, &, &&, All
			Menu, %CurrentMenu%, Add, %phrase%, MenuDummy
		} Else If RegExMatch(A_LoopReadLine,"^@([A-Za-z0-9]+)", para)
		{ ;Paraphrase: @abc Long Text will display abc but insert 'Long Text'
			Menu, %CurrentMenu%, Add, @%para1%, MenuPara
      %para1% := Trim(SubStr(A_LoopReadLine,InStr(A_LoopReadLine," ")+1))
		} Else If RegExMatch(A_LoopReadLine,"^\[(.+)\]",catname)
		{ ; Category Name is saved as TheCatName since catname1 is overwritten
			StringReplace, TheCatName, catname1, &, &&, All
			CurrentMenu=%TheCatName%
			InSubmenu=1
		} Else If A_LoopReadLine ; not blank
		{
			StringReplace, phrase, A_LoopReadLine, &, &&, All
			Menu, %CurrentMenu%, Add, %phrase%, MenuClick
		}
	}
} Else
	MsgBox, 16, PhraseOMatic, Cannot find %PhraseFile%
Menu, tray, add  ; Creates a separator line.
Menu, tray, add, Create File..., MenuCreateFile
Menu, tray, add, Add File..., MenuAddFile
Menu, tray, add, Remove File..., MenuRemoveFile
Menu, tray, add  ; Creates a separator line.
IfEqual, HasRegistry, 1
{
	Loop, HKCU, Software\PhraseOMatic,1,0
	{
		If A_LoopRegName
		{
			Menu, tray, add, %A_LoopRegName%, MenuSetDefault
			RegRead, f_MenuPhrasePath
			IfEqual, f_MenuPhrasePath, %PhraseFile%
				Menu, tray, check, %A_LoopRegName%
		}
	}
	Menu, tray, add  ; Creates a separator line.
}
Shortcut = %A_Startup%\Shortcut to PhraseOMatic.lnk
Menu, tray, add, Create Shortcut in Startup Folder, MenuCreateShortcut
IfExist %Shortcut%
	Menu, tray, Disable, Create Shortcut in Startup Folder
Menu, tray, add, Edit Phrases, MenuNotepad
Menu, tray, Default, Edit Phrases
Menu, tray, add, Path: %f_PhrasePath%, MenuGoPath
Return

;_____Hotkey and Label Section_____
~F6::
	Menu, PhraseMenu, Show
Return

MenuCreateShortcut:
	FileCreateShortcut, %A_ScriptFullPath%, %Shortcut%
	Reload
Return

MenuAddFile:
	FileSelectFile, AddedFile, 3, %f_PhrasePath%, Select Phrase File, PhraseOMatic Text Files (*.txt)
	IfExist, %AddedFile%
	{
		InputBox, AddedName, Name This PhraseOMatic File, Provide a brief (1- or 2- word) name for this file,,,,,,,,Added PhraseFile
		RegWrite,REG_SZ, HKCU, Software\PhraseOMatic, %AddedName%, %AddedFile%
		RegWrite,REG_SZ, HKCU, Software\PhraseOMatic,, %AddedFile%
		MsgBox,,%AddedName% Added,The Phrasefile %AddedName% is now the default.`nUse the right-click menu on the tray icon to change.
		Reload
	}
Return

MenuCreateFile:
	InputBox, CreatedName, Name This PhraseOMatic File, Provide a brief (1- or 2- word) name for this new file,,,,,,,,New PhraseFile
	FileSelectFile, CreatedFile, S24, %f_PhrasePath%, Create Phrase File, PhraseOMatic Text Files (*.txt)
	FileAppend,
(
;MenuTitle:PhraseOMatic - %CreatedName%
;ToolTip:PhraseOMatic 1.1.0 (F6)
;Shell32.dll Icon:47
;  Certain first characters on a line have special meaning:
;  [] Encloses a Submenu Name, e.g., [Companies]
;  / Ends a Submenu Block
;  - Inserts a Separator Line
;  ; Comment (non-displaying)
;  > Comment (displays but does nothing if clicked)
;  @term Definition displays @term but inserts Definition
;<---- Add / Edit Text Items Below This Line ---->
>PhraseOMatic Sample Text
>Double-click the tray icon to edit this file

),%CreatedFile%
	MsgBox,64,Created File,Save and Close Notepad after Adding Data
	RunWait, Notepad.exe %CreatedFile%
	RegWrite,REG_SZ, HKCU, Software\PhraseOMatic, %CreatedName%, %CreatedFile%
	RegWrite,REG_SZ, HKCU, Software\PhraseOMatic,, %CreatedFile%
	MsgBox,64,%CreatedName% Created,The Phrasefile %CreatedName% is now the default.`nUse the right-click menu on the tray icon to change.
	Reload
Return

MenuRemoveFile:
Gui, Add, Text,, Select the PhraseFile name to remove from the menu`n(note you cannot delete the currently active Phrase File). `nThis does not delete any files from the disk drive.`nTo cancel, press ESCAPE or close this window.
Gui, Add, ListBox, vMyListBox gMyListBox w240 r10
Gui, Add, Button, Default, OK
Loop, HKCU, Software\PhraseOMatic,1,0
{
	If A_LoopRegName ;I think this will not list the active Phrase File in the list box to be deleted
  {
    RegRead, f_MenuPhrasePath
		IfNotEqual, f_MenuPhrasePath, %PhraseFile%
  		GuiControl,, MyListBox, %A_LoopRegName%
  }
}
Gui, Show
Return

MenuNotepad:
	RunWait, Notepad.exe %PhraseFile%
	Reload
Return

MenuGoPath:
	Run, Explorer.exe %f_PhrasePath%,,Max
Return

MenuSetDefault:
	Loop, HKCU, Software\PhraseOMatic,1,0
	{
		IfEqual, A_LoopRegName, %A_ThisMenuItem%
		{
			RegRead, f_MenuPhrasePath
			RegWrite, REG_SZ, HKCU, Software\PhraseOMatic,, %f_MenuPhrasePath%
			Break
		}
	}
	Reload
Return

MenuDummy:
Return

MenuClick:
  ; Replace double ampersand (&&) with single again
  StringReplace, phrase, A_ThisMenuItem, &&, &, All
MenuClick2:
	GetKeyState, state, Shift
	IfEqual,state,D
		Clipboard = %phrase%
	Else
	{
	WinActivate
	Loop, Parse, phrase, %A_Space%
		SendInput, {Raw}%A_LoopField%%A_Space%
}
	GetKeyState, state, Ctrl
	IfEqual,state,D
		Menu, PhraseMenu, Show
Return

MenuPara:
; Reset the stored value of the paraphrase variable
  Tmp1 := SubStr(A_ThisMenuItem,2)
  Tmp := %Tmp1%
  StringReplace, phrase, Tmp, &&, &, All
  Gosub, MenuClick2
Return

MyListBox:
If A_GuiEvent <> DoubleClick
    return
; Otherwise, the user double-clicked a list item, so treat that the same as pressing OK.
; So fall through to the next label.
ButtonOK:
GuiControlGet, MyListBox  ; Retrieve the ListBox's current selection.
MsgBox, 4,, Would you you like to remove %MyListBox%?
IfMsgBox, No
{
	Gui, Destroy
  Return
}
RegDelete, HKCU, Software\PhraseOMatic, %MyListBox%
MsgBox,64,Removed PhraseFile,The Phrasefile %MyListBox% was removed.
Gui, Destroy
Reload
Return

GuiClose:
GuiEscape:
Gui, Destroy
return