Most efficient way to use hotstrings for dates

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Excrubulent
Posts: 28
Joined: 24 Jun 2014, 20:47

Most efficient way to use hotstrings for dates

04 Aug 2014, 20:28

I'm a transcriptionist, and I'm trying to find a way to shortcut dates. The trick is, we need to type a hard space in between the day and the month, so it's 1^+{Space}January as the output. That's fine, but there are some challenges to defining the hotstrings for this, because ^+{Space} isn't recognised by default as a punctuation symbol, and I don't know how to make it so. Here are the methods I've thought of, in order of preference:
  1. Define ^+{Space} as a punctuation symbol for all my hotstrings, so adding a hard space doesn't mess up the hotstring detection. This would solve a number of problems for me in my transcript hotstrings.
  2. Find some way to define parametric numbers at the start of the hotstring and use them in the output. Would probably be complex, but at least I could just type 1jan and get the appropriate output.
  3. Just make a hotstring for every day of the year, starting with ::1jan::1^+{Space}January and finishing with ::31dec::31^+{Space}December. That's 366 hostrings, which I'd rather not do. It's okay with things like 1^+{Space}o'clock, because there's only 12 of them, but 366 is getting out of hand. At least it would be faster to use than my current system.
  4. Make a dialog activated by ^!d which parses a date and types out the result. This is annoying because it's slow to use, and the point is to be fast, but it's what I've got right now.
Any ideas? I don't know AHK deeply enough to figure out whether 1 or 2 are feasible.
Excrubulent
Posts: 28
Joined: 24 Jun 2014, 20:47

Re: Most efficient way to use hotstrings for dates

04 Aug 2014, 23:57

Actually, I thought of another way to accomplish 2 in my first post above. Would it be possible to examine the buffer of keypresses, so that you could have the hotstring ::jan::, then go back and see if, prior to the hotstring, a number was typed followed by a space. If so, just delete the space and replace with a hard space. Is this possible?
User avatar
berban
Posts: 97
Joined: 14 Apr 2014, 03:20

Re: Most efficient way to use hotstrings for dates

05 Aug 2014, 00:09

Well you could do #3 and use AutoHotkey to make the code

Code: Select all

months =
(
jan	January
feb	February
mar	March
apr	April
may	May
jun	June
jul	July
aug	August
sep	September
oct	October
nov	November
dec	December
)

Loop, Parse, months, `n, `r
{
	StringSplit, month, A_LoopField, %A_Tab%
	loop 31
		output .= "::" A_Index month1 "::" A_Index "^+{Space}" month2 "`r`n"
}

Clipboard := output
Stores the following into the clipboard:

Code: Select all

::1jan::1^+{Space}January
::2jan::2^+{Space}January
::3jan::3^+{Space}January
::4jan::4^+{Space}January
::5jan::5^+{Space}January
::6jan::6^+{Space}January
::7jan::7^+{Space}January
::8jan::8^+{Space}January
::9jan::9^+{Space}January
::10jan::10^+{Space}January
::11jan::11^+{Space}January
::12jan::12^+{Space}January
::13jan::13^+{Space}January
::14jan::14^+{Space}January
::15jan::15^+{Space}January
::16jan::16^+{Space}January
::17jan::17^+{Space}January
::18jan::18^+{Space}January
::19jan::19^+{Space}January
::20jan::20^+{Space}January
::21jan::21^+{Space}January
::22jan::22^+{Space}January
::23jan::23^+{Space}January
::24jan::24^+{Space}January
::25jan::25^+{Space}January
::26jan::26^+{Space}January
::27jan::27^+{Space}January
::28jan::28^+{Space}January
::29jan::29^+{Space}January
::30jan::30^+{Space}January
::31jan::31^+{Space}January
::1feb::1^+{Space}February
::2feb::2^+{Space}February
::3feb::3^+{Space}February
::4feb::4^+{Space}February
::5feb::5^+{Space}February
::6feb::6^+{Space}February
::7feb::7^+{Space}February
::8feb::8^+{Space}February
::9feb::9^+{Space}February
::10feb::10^+{Space}February
::11feb::11^+{Space}February
::12feb::12^+{Space}February
::13feb::13^+{Space}February
::14feb::14^+{Space}February
::15feb::15^+{Space}February
::16feb::16^+{Space}February
::17feb::17^+{Space}February
::18feb::18^+{Space}February
::19feb::19^+{Space}February
::20feb::20^+{Space}February
::21feb::21^+{Space}February
::22feb::22^+{Space}February
::23feb::23^+{Space}February
::24feb::24^+{Space}February
::25feb::25^+{Space}February
::26feb::26^+{Space}February
::27feb::27^+{Space}February
::28feb::28^+{Space}February
::29feb::29^+{Space}February
::30feb::30^+{Space}February
::31feb::31^+{Space}February
::1mar::1^+{Space}March
::2mar::2^+{Space}March
::3mar::3^+{Space}March
::4mar::4^+{Space}March
::5mar::5^+{Space}March
::6mar::6^+{Space}March
::7mar::7^+{Space}March
::8mar::8^+{Space}March
::9mar::9^+{Space}March
::10mar::10^+{Space}March
::11mar::11^+{Space}March
::12mar::12^+{Space}March
::13mar::13^+{Space}March
::14mar::14^+{Space}March
::15mar::15^+{Space}March
::16mar::16^+{Space}March
::17mar::17^+{Space}March
::18mar::18^+{Space}March
::19mar::19^+{Space}March
::20mar::20^+{Space}March
::21mar::21^+{Space}March
::22mar::22^+{Space}March
::23mar::23^+{Space}March
::24mar::24^+{Space}March
::25mar::25^+{Space}March
::26mar::26^+{Space}March
::27mar::27^+{Space}March
::28mar::28^+{Space}March
::29mar::29^+{Space}March
::30mar::30^+{Space}March
::31mar::31^+{Space}March
::1apr::1^+{Space}April
::2apr::2^+{Space}April
::3apr::3^+{Space}April
::4apr::4^+{Space}April
::5apr::5^+{Space}April
::6apr::6^+{Space}April
::7apr::7^+{Space}April
::8apr::8^+{Space}April
::9apr::9^+{Space}April
::10apr::10^+{Space}April
::11apr::11^+{Space}April
::12apr::12^+{Space}April
::13apr::13^+{Space}April
::14apr::14^+{Space}April
::15apr::15^+{Space}April
::16apr::16^+{Space}April
::17apr::17^+{Space}April
::18apr::18^+{Space}April
::19apr::19^+{Space}April
::20apr::20^+{Space}April
::21apr::21^+{Space}April
::22apr::22^+{Space}April
::23apr::23^+{Space}April
::24apr::24^+{Space}April
::25apr::25^+{Space}April
::26apr::26^+{Space}April
::27apr::27^+{Space}April
::28apr::28^+{Space}April
::29apr::29^+{Space}April
::30apr::30^+{Space}April
::31apr::31^+{Space}April
::1may::1^+{Space}May
::2may::2^+{Space}May
::3may::3^+{Space}May
::4may::4^+{Space}May
::5may::5^+{Space}May
::6may::6^+{Space}May
::7may::7^+{Space}May
::8may::8^+{Space}May
::9may::9^+{Space}May
::10may::10^+{Space}May
::11may::11^+{Space}May
::12may::12^+{Space}May
::13may::13^+{Space}May
::14may::14^+{Space}May
::15may::15^+{Space}May
::16may::16^+{Space}May
::17may::17^+{Space}May
::18may::18^+{Space}May
::19may::19^+{Space}May
::20may::20^+{Space}May
::21may::21^+{Space}May
::22may::22^+{Space}May
::23may::23^+{Space}May
::24may::24^+{Space}May
::25may::25^+{Space}May
::26may::26^+{Space}May
::27may::27^+{Space}May
::28may::28^+{Space}May
::29may::29^+{Space}May
::30may::30^+{Space}May
::31may::31^+{Space}May
::1jun::1^+{Space}June
::2jun::2^+{Space}June
::3jun::3^+{Space}June
::4jun::4^+{Space}June
::5jun::5^+{Space}June
::6jun::6^+{Space}June
::7jun::7^+{Space}June
::8jun::8^+{Space}June
::9jun::9^+{Space}June
::10jun::10^+{Space}June
::11jun::11^+{Space}June
::12jun::12^+{Space}June
::13jun::13^+{Space}June
::14jun::14^+{Space}June
::15jun::15^+{Space}June
::16jun::16^+{Space}June
::17jun::17^+{Space}June
::18jun::18^+{Space}June
::19jun::19^+{Space}June
::20jun::20^+{Space}June
::21jun::21^+{Space}June
::22jun::22^+{Space}June
::23jun::23^+{Space}June
::24jun::24^+{Space}June
::25jun::25^+{Space}June
::26jun::26^+{Space}June
::27jun::27^+{Space}June
::28jun::28^+{Space}June
::29jun::29^+{Space}June
::30jun::30^+{Space}June
::31jun::31^+{Space}June
::1jul::1^+{Space}July
::2jul::2^+{Space}July
::3jul::3^+{Space}July
::4jul::4^+{Space}July
::5jul::5^+{Space}July
::6jul::6^+{Space}July
::7jul::7^+{Space}July
::8jul::8^+{Space}July
::9jul::9^+{Space}July
::10jul::10^+{Space}July
::11jul::11^+{Space}July
::12jul::12^+{Space}July
::13jul::13^+{Space}July
::14jul::14^+{Space}July
::15jul::15^+{Space}July
::16jul::16^+{Space}July
::17jul::17^+{Space}July
::18jul::18^+{Space}July
::19jul::19^+{Space}July
::20jul::20^+{Space}July
::21jul::21^+{Space}July
::22jul::22^+{Space}July
::23jul::23^+{Space}July
::24jul::24^+{Space}July
::25jul::25^+{Space}July
::26jul::26^+{Space}July
::27jul::27^+{Space}July
::28jul::28^+{Space}July
::29jul::29^+{Space}July
::30jul::30^+{Space}July
::31jul::31^+{Space}July
::1aug::1^+{Space}August
::2aug::2^+{Space}August
::3aug::3^+{Space}August
::4aug::4^+{Space}August
::5aug::5^+{Space}August
::6aug::6^+{Space}August
::7aug::7^+{Space}August
::8aug::8^+{Space}August
::9aug::9^+{Space}August
::10aug::10^+{Space}August
::11aug::11^+{Space}August
::12aug::12^+{Space}August
::13aug::13^+{Space}August
::14aug::14^+{Space}August
::15aug::15^+{Space}August
::16aug::16^+{Space}August
::17aug::17^+{Space}August
::18aug::18^+{Space}August
::19aug::19^+{Space}August
::20aug::20^+{Space}August
::21aug::21^+{Space}August
::22aug::22^+{Space}August
::23aug::23^+{Space}August
::24aug::24^+{Space}August
::25aug::25^+{Space}August
::26aug::26^+{Space}August
::27aug::27^+{Space}August
::28aug::28^+{Space}August
::29aug::29^+{Space}August
::30aug::30^+{Space}August
::31aug::31^+{Space}August
::1sep::1^+{Space}September
::2sep::2^+{Space}September
::3sep::3^+{Space}September
::4sep::4^+{Space}September
::5sep::5^+{Space}September
::6sep::6^+{Space}September
::7sep::7^+{Space}September
::8sep::8^+{Space}September
::9sep::9^+{Space}September
::10sep::10^+{Space}September
::11sep::11^+{Space}September
::12sep::12^+{Space}September
::13sep::13^+{Space}September
::14sep::14^+{Space}September
::15sep::15^+{Space}September
::16sep::16^+{Space}September
::17sep::17^+{Space}September
::18sep::18^+{Space}September
::19sep::19^+{Space}September
::20sep::20^+{Space}September
::21sep::21^+{Space}September
::22sep::22^+{Space}September
::23sep::23^+{Space}September
::24sep::24^+{Space}September
::25sep::25^+{Space}September
::26sep::26^+{Space}September
::27sep::27^+{Space}September
::28sep::28^+{Space}September
::29sep::29^+{Space}September
::30sep::30^+{Space}September
::31sep::31^+{Space}September
::1oct::1^+{Space}October
::2oct::2^+{Space}October
::3oct::3^+{Space}October
::4oct::4^+{Space}October
::5oct::5^+{Space}October
::6oct::6^+{Space}October
::7oct::7^+{Space}October
::8oct::8^+{Space}October
::9oct::9^+{Space}October
::10oct::10^+{Space}October
::11oct::11^+{Space}October
::12oct::12^+{Space}October
::13oct::13^+{Space}October
::14oct::14^+{Space}October
::15oct::15^+{Space}October
::16oct::16^+{Space}October
::17oct::17^+{Space}October
::18oct::18^+{Space}October
::19oct::19^+{Space}October
::20oct::20^+{Space}October
::21oct::21^+{Space}October
::22oct::22^+{Space}October
::23oct::23^+{Space}October
::24oct::24^+{Space}October
::25oct::25^+{Space}October
::26oct::26^+{Space}October
::27oct::27^+{Space}October
::28oct::28^+{Space}October
::29oct::29^+{Space}October
::30oct::30^+{Space}October
::31oct::31^+{Space}October
::1nov::1^+{Space}November
::2nov::2^+{Space}November
::3nov::3^+{Space}November
::4nov::4^+{Space}November
::5nov::5^+{Space}November
::6nov::6^+{Space}November
::7nov::7^+{Space}November
::8nov::8^+{Space}November
::9nov::9^+{Space}November
::10nov::10^+{Space}November
::11nov::11^+{Space}November
::12nov::12^+{Space}November
::13nov::13^+{Space}November
::14nov::14^+{Space}November
::15nov::15^+{Space}November
::16nov::16^+{Space}November
::17nov::17^+{Space}November
::18nov::18^+{Space}November
::19nov::19^+{Space}November
::20nov::20^+{Space}November
::21nov::21^+{Space}November
::22nov::22^+{Space}November
::23nov::23^+{Space}November
::24nov::24^+{Space}November
::25nov::25^+{Space}November
::26nov::26^+{Space}November
::27nov::27^+{Space}November
::28nov::28^+{Space}November
::29nov::29^+{Space}November
::30nov::30^+{Space}November
::31nov::31^+{Space}November
::1dec::1^+{Space}December
::2dec::2^+{Space}December
::3dec::3^+{Space}December
::4dec::4^+{Space}December
::5dec::5^+{Space}December
::6dec::6^+{Space}December
::7dec::7^+{Space}December
::8dec::8^+{Space}December
::9dec::9^+{Space}December
::10dec::10^+{Space}December
::11dec::11^+{Space}December
::12dec::12^+{Space}December
::13dec::13^+{Space}December
::14dec::14^+{Space}December
::15dec::15^+{Space}December
::16dec::16^+{Space}December
::17dec::17^+{Space}December
::18dec::18^+{Space}December
::19dec::19^+{Space}December
::20dec::20^+{Space}December
::21dec::21^+{Space}December
::22dec::22^+{Space}December
::23dec::23^+{Space}December
::24dec::24^+{Space}December
::25dec::25^+{Space}December
::26dec::26^+{Space}December
::27dec::27^+{Space}December
::28dec::28^+{Space}December
::29dec::29^+{Space}December
::30dec::30^+{Space}December
::31dec::31^+{Space}December
Excrubulent
Posts: 28
Joined: 24 Jun 2014, 20:47

Re: Most efficient way to use hotstrings for dates

05 Aug 2014, 02:01

Yeah, thanks, I could do that. I could also use the #include directive and put the mass of dates into its own separate script, to make it easier to maintain. I just means that I have to re-solve this problem for every situation where I've got a hard space and I still want to use hotstrings.

For instance, I've also got a hotstring ::exb::exhibit and another one :o:exba::exhibit^+{Space}, because I need a hard space between the word "exhibit" and whatever number is assigned to that exhibit. If it were possible to use the hard space as punctuation, I wouldn't need workarounds like this.
Guest

Re: Most efficient way to use hotstrings for dates

05 Aug 2014, 03:21

You could do that with RegEx powered hotstrings - just a few lines of code http://www.autohotkey.com/board/topic/1 ... otstrings/ - note that it may interfere with other hotstring scripts so ymmv.

For your date problem it could be like this

--------------
; don't forget to add hotstrings.ahk to your LIB folder or #include it

#SingleInstance, force

months:={ jan: "January", feb: "February", mar: "March", apr: "April", may: "May"
, jun: "June", jul: "July", aug: "August", sep: "September"
, oct: "October", nov: "November", dec: "December" }

hotstrings("(\d{1,2})(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)", "printdate")
Return

printdate:
day:=$1
mon:=months[$2]
Send %day%^+{space}%mon%
Return

---------------

for others you could setup another hotstrings() below the first one but above the return
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Most efficient way to use hotstrings for dates

05 Aug 2014, 04:21

Excrubulent wrote:I'm a transcriptionist, and I'm trying to find a way to shortcut dates. The trick is, we need to type a hard space in between the day and the month, so it's 1^+{Space}January as the output. That's fine, but there are some challenges to defining the hotstrings for this, because ^+{Space} isn't recognised by default as a punctuation symbol, and I don't know how to make it so. Here are the methods I've thought of, in order of preference:
So you want to use the non-breaking space as a trigger? Any reason you don't want to use a regular space?
Define ^+{Space} as a punctuation symbol for all my hotstrings, so adding a hard space doesn't mess up the hotstring detection. This would solve a number of problems for me in my transcript hotstrings.
Hotstring detection resets after a press of control, so the way MS Word inserts that space won't work. Same for alt, so you can't use {asc 0160}. You could look into dynamic hotstrings and do some editing to ignore the control as a reset and add a non-breaking space as interpunction.

Code: Select all

for abbr,full in {jan:"January", feb:"February", mar:"March", apr:"April", may:"May", jun:"June", jul:"July", aug:"August", sep:"September", oct:"October", nov:"November", dec:"December" }
Hotstring("(\d{1,2}) " abbr,"$1 " full,3)
Find some way to define parametric numbers at the start of the hotstring and use them in the output. Would probably be complex, but at least I could just type 1jan and get the appropriate output.
If you use the month abbreviations as triggers, you could send a +{Right 2}^x to cut the month and phrase preceding it, check if it's a number, and output the modified string.
Excrubulent
Posts: 28
Joined: 24 Jun 2014, 20:47

Re: Most efficient way to use hotstrings for dates

05 Aug 2014, 20:05

Nextron wrote:So you want to use the non-breaking space as a trigger? Any reason you don't want to use a regular space?
Because...
Excrubulent wrote:we need to type a hard space in between the day and the month
Seriously, that's the reason. It's my job. The Court gets angry if the day and the month are on separate lines. They also get antsy if "Mr" and "Smith" are on separate lines, and "his" and "Honour", and measurements and their units, street numbers and names, "cross-" and "examination", "voir" and "dire", "et" and "cetera". There are a lot of rules about how things are to be typed. They are very, very specific.

I mean, as has been noted, there are ways around this limitation, which is why I'm here. I'd rather not have to type the non-breaking space if I can avoid it, because it adds a small amount of time and effort to my typing, which adds up over the day. So finding a way to type "1jan" and have the date expand for me would be ideal.

Anyway, lots of solutions here, I'll see which ones work for me and report back on my results.
Excrubulent
Posts: 28
Joined: 24 Jun 2014, 20:47

Re: Most efficient way to use hotstrings for dates

05 Aug 2014, 21:25

Guest wrote:You could do that with RegEx powered hotstrings - just a few lines of code http://www.autohotkey.com/board/topic/1 ... otstrings/ - note that it may interfere with other hotstring scripts so ymmv.

For your date problem it could be like this

--------------
; don't forget to add hotstrings.ahk to your LIB folder or #include it

#SingleInstance, force

months:={ jan: "January", feb: "February", mar: "March", apr: "April", may: "May"
, jun: "June", jul: "July", aug: "August", sep: "September"
, oct: "October", nov: "November", dec: "December" }

hotstrings("(\d{1,2})(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)", "printdate")
Return

printdate:
day:=$1
mon:=months[$2]
Send %day%^+{space}%mon%
Return

---------------

for others you could setup another hotstrings() below the first one but above the return

Kaboom, killed it. The only change I had to make was changing Send to SendInput, otherwise whatever character I type at the end of the hotstring gets inserted somewhere in the middle of the output. It doesn't interfere with my other hotstrings, and because my other hotstrings don't start with numbers usually, it doesn't matter that it's not waiting for an ending character. I'll let you know how I go with this after a day or two of use.

EDIT: I will also check out Nextron's method soon.
Last edited by Excrubulent on 19 Oct 2014, 22:33, edited 1 time in total.
Excrubulent
Posts: 28
Joined: 24 Jun 2014, 20:47

Re: Most efficient way to use hotstrings for dates

19 Oct 2014, 22:29

I've been using the script here for a while for dates, but every time I try to write my own function, it just doesn't work. For instance, I've added the following to the script:

Code: Select all

#Include C:\<path>\Hotstrings.ahk

; dates

months:={ jan: "January", feb: "February", mar: "March", apr: "April", may: "May"
, jun: "June", jul: "July", aug: "August", sep: "September"
, oct: "October", nov: "November", dec: "December" }

hotstrings("(\d{1,2})(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)", "printdate")
Return

printdate:
day:=$1
mon:=months[$2]
SendInput %day%^+{space}%mon%
Return

; numbered things

hotstrings("(nmb)(\d{1,2})", "numberX")
Return

numberX:
num:=$2
SendInput number^+{Space}%num%
Return
The first mention of hotstrings works, but the second doesn't. I've tried reversing the order of the hotstrings functions, and only the first mention of hotstrings in the file ever works. What's going on here? I can't have more than one use of hotstrings per script? That seems kind of limited.
lexikos
Posts: 9621
Joined: 30 Sep 2013, 04:07
Contact:

Re: Most efficient way to use hotstrings for dates

19 Oct 2014, 23:48

There is nothing indicating when your second call to hotstrings should be executed (like a label, hotkey or hotstring). So it isn't.

See The Top of the Script (the Auto-execute Section).
Excrubulent
Posts: 28
Joined: 24 Jun 2014, 20:47

Re: Most efficient way to use hotstrings for dates

19 Oct 2014, 23:55

lexikos wrote:There is nothing indicating when your second call to hotstrings should be executed (like a label, hotkey or hotstring). So it isn't.

See The Top of the Script (the Auto-execute Section).

From what I can see, there is nothing indicating when the first call should be executed, so why is it?
Guest

Re: Most efficient way to use hotstrings for dates

20 Oct 2014, 01:18

You need to move your "; numbered things" hotstrings() just below the first hotstrings() and ABOVE the first return. The script "stops" (auto-execute) after the first Return so your "; numbered things" function is never executed so they won't be set as a hotstring and therefore fail. You can have several hotstrings() in one script if you all place them beneath each other above the first Return.
Excrubulent
Posts: 28
Joined: 24 Jun 2014, 20:47

Re: Most efficient way to use hotstrings for dates

20 Oct 2014, 18:59

Guest wrote:You need to move your "; numbered things" hotstrings() just below the first hotstrings() and ABOVE the first return. The script "stops" (auto-execute) after the first Return so your "; numbered things" function is never executed so they won't be set as a hotstring and therefore fail. You can have several hotstrings() in one script if you all place them beneath each other above the first Return.
I see, so Hotstrings is a function that creates something persistent. I'll do that.
Excrubulent
Posts: 28
Joined: 24 Jun 2014, 20:47

Re: Most efficient way to use hotstrings for dates

27 Oct 2014, 18:42

I understand what's happening now - I use AHK essentially to make a list of hotstrings, usually. I haven't done much with it by way of function calls. So when I saw the hotstrings function, I didn't realise that it was just a regular function call, and I was thinking it would behave just like all the other hotstrings in my script, so you could place it almost anywhere and it would just be picked up and work.

That said, linking to a large docs page isn't really an answer, and it didn't help me. The Guest answer actually gave me enough information for me to figure out my misunderstanding.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada and 132 guests