Skip to content

Instantly share code, notes, and snippets.

@davebrny
Last active March 10, 2019 14:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davebrny/c8fc4dd7af299afe5ec8883faa28784a to your computer and use it in GitHub Desktop.
Save davebrny/c8fc4dd7af299afe5ec8883faa28784a to your computer and use it in GitHub Desktop.
💬 (autohotkey) - message commands that are quick to type and easy to switch between
msg_box(string=". . .", options="") {
string := format_text(string, options)
msgBox, % string
}
msg_tray(string=". . .", options="") {
string := format_text(string, options)
trayTip, , % string, 10
}
msg_tool(string=". . .", options="") {
string := format_text(string, options)
toolTip, % string
setTimer, tool_timer, 2000
}
msg_splash(string=". . .", options="") {
global msg_splash
msg_splash := format_text(string, options)
progress, b w700 zh0 c0 fs20 ws1000 ct969696, % msg_splash, , , consolas
setTimer, splash_timer, 2000
}
format_text(string, options) {
if options is not alpha
{
for what, with in {"1":"c", "2":"q", "3":"a"}
stringReplace, options, options, % what, % with, all
}
; show spaces
if inStr(options, "`s")
stringReplace, string, string, % a_space, ``s, all
; show tabs
if inStr(options, "`t")
stringReplace, string, string, % a_tab, ``tttt, all
; show linefeeds
obfuscate = "!su^V*3cjT#&m|Y>Ut~0J\w@s?=Qyl8-bX9a"
if inStr(options, "`r`n")
stringReplace, string, string, `r`n, % obfuscate, all
if inStr(options, "`n")
stringReplace, string, string, `n, ``n`n, all
if inStr(options, "`r")
stringReplace, string, string, `r, ``r`r, all
if inStr(string, obfuscate)
stringReplace, string, string, % obfuscate, ``r``n`r`n , all
; wrap text in symbols
linefeed := inStr(string, "`r`n") ? ("`r`n") : ("`n")
if inStr(options, "q")
{
stringReplace, string, string, % linefeed, % """" linefeed """", all
string = "%string%"
}
else if inStr(options, "a")
{
stringReplace, string, string, % linefeed, % "<" linefeed ">", all
string = >%string%<
}
; copy to clipboard
if inStr(options, "c")
clipboard = %string%
return string
}
tool_timer(){
tool_id := winExist("ahk_class tooltips_class32")
mouseGetPos, , , id_under ; under cursor
if (id_under != tool_id)
{
setTimer, tool_timer, off
toolTip,
}
}
splash_timer(){
global msg_splash
mouseGetPos, , , window_under
winGetText, text_under, ahk_id %window_under%
if !inStr(text_under, msg_splash)
{
setTimer, splash_timer, off
progress, off
}
}
/*
[script info]
version = 2.6
description = message commands that are quick to type and easy to switch between
author = davebrny
source = https://gist.github.com/davebrny/c8fc4dd7af299afe5ec8883faa28784a
*/
::mbox::
::mtray::
::mtool::
::msplash::
stringReplace, this_label, a_thisLabel, ::m, msg_
clipboard_revert := clipboardAll
clipboard = %this_label%("text")
send ^{v}{left}+{left 6}
clipboard := clipboard_revert
return
@davebrny
Copy link
Author

davebrny commented Feb 12, 2017

quick msg

message commands that are quick to type and easy to switch between

msg_box()
msg_tray()
msg_tool()
msg_splash()

since these were made with quick string debugging in mind, only the text parameter is used and the unimportant things like title text and timeout options are left out or set to defaults.

- to check for trailing spaces or linefeeds add q or a to the second parameter.
- add a space, tab or linefeed to show those invisible characters as text.
- add c to have the message contents added to the clipboard.
- hover the cursor over a tooltip or splash window to stop it from closing.
- switch between message types by changing the name after msg_ to box, tray, tool or splash.
- the text parameter can be left blank if you just want test whether part of your code is being run or not

put msg.ahk into your user library so you wont have to #include it in every new script you make


 

options:

letter #
c 1 add msg to the clipboard
q 2 show msg between "quotes"
a 3 show msg between >arrows<
`s show spaces
`t show tabs
`n show linefeeds
`r show carriage return

msg_box(string, "ac")
msg_box(string, 31)
msg_box(string, "`r`n")

 

sublime snippets: ➜ download

function trigger
msg_box("text") mbox
msg_tray("text") mtray
msg_tool("text") mtool
msg_splash("text") msplash
  • when the snippets are used, the quotes and text will be selected first.
    press the tab key to move the selection inside the quotes

  • the snippets can be typed quickly with just a few keystrokes: mb, mtr, mt, ms

if you dont use sublime text then the hotstrings in msg hotstrings.ahk will do pretty much the same thing

 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment