Quick-entry date tool, feedback welcome.

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
kunkel321
Posts: 1194
Joined: 30 Nov 2015, 21:19

Quick-entry date tool, feedback welcome.

23 Dec 2015, 13:53

Hopefully this is working well enough for this sub forum (still basicaly a n00by here).
It's for entering today's date with the hotstring ;d0 (semi-colon dee zero). future dates are ;d1 for tomorrow, and so on up to ;d9 for nine days from now. Days in the past are ;dd1 for yesterday, and so on to ;dd9 for nine days ago. I work as a school psychologist in a public school district. There is a surprising number of times I need to enter dates into things! To help ensure that I've inserted the correct date, a tooltip pops up near the entry point, indicating the weekday. If I accidentally enter a Sat or Sun I get a warning dialog. (For some reason teachers don't like it if you schedule meetings on weekends! LOL.) As an afterthought, I added the built in AHK popup date GUI, activated via ;dp (DP for "date picker") The primary app we use for generating legal documents is a webapp called GoalView. It only likes "M/d/yyyy" as a date format. I prefer "M-d-yyyy" so I can use it in file names and such. So I made the script detect if GoalView is the active window, and act accordingly. I was not able to get the GUI to work correctly inline with all the variables that are associated with the date-offsetting, so I ended up just putting it at the bottom and having the InWinActive, GoalView part replicated at the bottom. Folks are welcome to comment it they can think of ways to handle that more gracefully.... Or any other general stylistic or functional comments are also welcome :) Oh, also I thought I'd share it with coworkers, so I made the "M-d-yyyy" format changeable via an included text file (that is really an INI file with a TXT extension).

EDIT: Condensed first portion of script (see first two replies, below; Thanks for the awesome tips!). Also added Esc:: and Gui close near the bottom.
It occurs to me that this has more of a "help" thread, then a "share" thread....
Mods: Please consider moving this whole thread to the "Help" subforum, if appropriate.

Code: Select all

#NoEnv ; For security
#SingleInstance force
;==================================================================
; Current date is ";d0"   DatePicker GUI is ;dp
; Dates in the future are ";dn" where n = number of days.  (Max 9)
; Dates in the past are ";ddn" where n = number of day. (Max 9)
:?*:;dd9::
:?*:;dd8::
:?*:;dd7::
:?*:;dd6::
:?*:;dd5::
:?*:;dd4::
:?*:;dd3::
:?*:;dd2::
:?*:;dd1::
:?*:;d0::
:?*:;d1::
:?*:;d2::
:?*:;d3::
:?*:;d4::
:?*:;d5::
:?*:;d6::
:?*:;d7::
:?*:;d8::
:?*:;d9::

   StringReplace,nOffset,A_ThisHotkey,:?*:;d 
   StringReplace,nOffset,nOffset,d,- ; This first part condenced with help form forum members :)

Offset += %nOffset%, days ; Puts offset into date format.
SetTitleMatchMode, 2
IfWinActive, GoalView 
{
   FormatTime, MyDate, %OffSet%, M/d/yyyy
}
else 
{
	IniRead, dateFormat, DateFormat.txt, Date tool, Format, M/d/yyyy
    FormatTime, MyDate, %OffSet%, %dateFormat%
 }
SendInput, %MyDate%   ; This types out the date.

FormatTime, DOWtoday ,,WDay ;====== This is all for the tooltip/popup.====
DOWsum := $ DOWtoday + nOffset ; "DOW" is "day or week," not "Dow Jones."
if (DOWsum > 7) 
	MySuffix = `, next week
else if (DOWsum > 14)
	MySuffix = `, week after next
else if (DOWsum < -1)
	MySuffix = `, last week
else if (DOWsum < -8)
	MySuffix = `, week before last
else
	MySuffix = 
myToolTipX := A_CaretX + 10 ; For position of tooltip.
myToolTipY := A_CaretY + 25

FormatTime, DayOfWeek, %OffSet%, dddd
If (DayOfWeek = "Saturday") || (DayOfWeek = "Sunday") {
   MsgBox, 48, , WARNING:`n`nThat falls on a weekend.`n`n     %DayOfWeek%
}
else
   ToolTip, %DayOfWeek%%MySuffix%, %myToolTipX%, %myToolTipY%
SetTimer, RemoveToolTip, 2000
OffSet =		; Reset to nothing.
nOffset =
return

RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip 
return  ;========== End of Tooltip section ================
   
:?*:;dp:: ;=========== Popup calendar ===============
	Gui, dp:Add, MonthCal, vOffSet
	Gui, dp:Add, Button, Default, Submit 
	Gui, dp:Show ,,Date Picker
Return
dpButtonSubmit: 
	Gui, dp:Submit
SetTitleMatchMode, 2
IfWinActive, GoalView 
{
   FormatTime, MyDate, %OffSet%, M/d/yyyy
}
else 
{
	IniRead, dateFormat, DateFormat.txt, Date tool, Format, M/d/yyyy
    FormatTime, MyDate, %OffSet%, %dateFormat%
 }
SendInput, %MyDate%   ; This types out the date.
Esc::
dpGuiClose:
	Gui, dp:Destroy 
Return


Text file to be named "DateFormat.txt" and be put in same dir.

Code: Select all

[Date tool]
Format=M-d-yyyy
;The part after "Format=" is the format.
;Is uses the Date Formats (CaSe SensiTiVe)from AutoHotkey manual.
;d 	= Day of the month without leading zero (1 - 31) 
;dd 	= Day of the month with leading zero (01 – 31) 
;ddd 	= Abbreviated name for the day of the week (e.g. Mon) in the current user's language 
;dddd 	= Full name for the day of the week (e.g. Monday) in the current user's language 
;M 	= Month without leading zero (1 – 12) (WARNING: lower 'm' = 'Minutes')
;MM 	= Month with leading zero (01 – 12) 
;MMM 	= Abbreviated month name (e.g. Jan) in the current user's language 
;MMMM 	= Full month name (e.g. January) in the current user's language 
;y 	= Year without century, without leading zero (0 – 99) 
;yy 	= Year without century, with leading zero (00 - 99) 
;yyyy 	= Year with century. For example: 2005 
;gg 	= Period/era string for the current user's locale (blank if none) 
Last edited by kunkel321 on 24 Dec 2015, 13:20, edited 1 time in total.
ste(phen|ve) kunkel
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Quick-entry date tool, feedback welcome.

23 Dec 2015, 14:57

Here is a little improvement so goto is not required:

Code: Select all

#NoEnv ; For security
#SingleInstance force
;==================================================================
; Steve's date scripts.  Current date is ";d0"
; Dates in the future are ";dn" where n = number of days.  (Max 9)
; Dates in the past are ";ddn" where n = number of day. (Max 9)
:?*:;dd9::
:?*:;dd8::
:?*:;dd7::
:?*:;dd6::
:?*:;dd5::
:?*:;dd4::
:?*:;dd3::
:?*:;dd2::
:?*:;dd1::
:?*:;d0::
:?*:;d1::
:?*:;d2::
:?*:;d3::
:?*:;d4::
:?*:;d5::
:?*:;d6::
:?*:;d7::
:?*:;d8::
:?*:;d9::
   StringReplace,nOffset,A_ThisHotkey,:?*:;d
   StringReplace,nOffset,nOffset,d,-
	; After the "offset" gets assigned above, this part of the script determines if you're in Goalview. 
	Offset += %nOffset%, days ; Puts offset into date format.
	SetTitleMatchMode, 2
	IfWinActive, GoalView 
	{
	   FormatTime, MyDate, %OffSet%, M/d/yyyy
	}
	else 
	{
		IniRead, dateFormat, DateFormat.txt, Date tool, Format, M/d/yyyy
		FormatTime, MyDate, %OffSet%, %dateFormat%
	 }
	SendInput, %MyDate%   ; This types out the date.
	 
	FormatTime, DOWtoday ,,WDay ;====== This is all for the tooltip/popup.====
	DOWsum := $ DOWtoday + nOffset ; "DOW" is "day or week," not "Dow Jones."
	if (DOWsum > 7) 
		MySuffix = `, next week
	else if (DOWsum > 14)
		MySuffix = `, week after next
	else if (DOWsum < -1)
		MySuffix = `, last week
	else if (DOWsum < -8)
		MySuffix = `, week before last
	else
		MySuffix = 
	myToolTipX := A_CaretX + 10 ; For position of tooltip.
	myToolTipY := A_CaretY + 25
	 
	FormatTime, DayOfWeek, %OffSet%, dddd
	If (DayOfWeek = "Saturday") || (DayOfWeek = "Sunday") {
	   MsgBox, 48, , WARNING:`n`nThat falls on a weekend.`n`n     %DayOfWeek%%MySuffix%
	}
	else
	   ToolTip, %DayOfWeek%%MySuffix%, %myToolTipX%, %myToolTipY%
	SetTimer, RemoveToolTip, 2000
	OffSet =		; Reset to nothing.
	nOffset =
return
 
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip 
return  ;========== End of Tooltip section ================
 
:?*:;dp:: ;=========== Popup calendar ===============
	Gui, dp:Add, MonthCal, vOffSet
	Gui, dp:Add, Button, Default, Submit 
	Gui, dp:Show ,,Date Picker
Return
dpButtonSubmit: 
	Gui, dp:Submit
	SetTitleMatchMode, 2
	IfWinActive, GoalView 
	{
	   FormatTime, MyDate, %OffSet%, M/d/yyyy
	}
	else 
	{
		IniRead, dateFormat, DateFormat.txt, Date tool, Format, M/d/yyyy
		FormatTime, MyDate, %OffSet%, %dateFormat%
	}
	SendInput, %MyDate%   ; This types out the date.
	 
	Gui, dp:Destroy 
Return
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: Quick-entry date tool, feedback welcome.

23 Dec 2015, 15:11

I generally prefer to avoid the use of GoTo whenever possible, so I eliminated it from your script by making the following changes (everything after DateSetter: is unchanged, so I did not include it below)...

Code: Select all

#NoEnv
#SingleInstance force
;==================================================================
; Steve's date scripts.  Current date is ";d0"
; Dates in the future are ";dn" where n = number of days.  (Max 9)
; Dates in the past are ";ddn" where n = number of day. (Max 9)
:?*:;dd9::
:?*:;dd8::
:?*:;dd7::
:?*:;dd6::
:?*:;dd5::
:?*:;dd4::
:?*:;dd3::
:?*:;dd2::
:?*:;dd1::
:?*:;d0::
:?*:;d1::
:?*:;d2::
:?*:;d3::
:?*:;d4::
:?*:;d5::
:?*:;d6::
:?*:;d7::
:?*:;d8::
:?*:;d9::
   If InStr(A_ThisHotkey, "dd")
      nOffset := "-" . SubStr(A_ThisHotkey,0)
   Else
         nOffset := SubStr(A_ThisHotkey,0)
 
DateSetter:   ; After the "offset" gets assigned above, this part of the script determines if you're in Goalview.
User avatar
kunkel321
Posts: 1194
Joined: 30 Nov 2015, 21:19

Re: Quick-entry date tool, feedback welcome.

23 Dec 2015, 15:41

AWESOME! Thanks for posting this! I didn't even know that the potential to do this existed...
This definitely makes the code leaner and meaner! :)

EDIT: Actually, the DateSetter: label can go away altogether. :clap:
ste(phen|ve) kunkel
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: Quick-entry date tool, feedback welcome.

23 Dec 2015, 15:53

kunkel321 wrote:Actually, the DateSetter: label can go away altogether. :clap:
I left it because I thought it made a decent section separator/identifier for the code that follows it. :)
User avatar
kunkel321
Posts: 1194
Joined: 30 Nov 2015, 21:19

Re: Quick-entry date tool, feedback welcome.

23 Dec 2015, 16:04

That's true I guess.
It occurred to me that the way to avoid adding that "IfWinActive" part multiple times is to have it in a Function, then call the function twice ;) Will do that next.
Also, right above the dpButtonSubmit: (for the GUI date picker) I added
Esc::
dpGuiClose:
I noticed that if it was closed via the red X in the corner, then the variable it uses didn't get destroyed. This caused an error upon re-launching the GUI. (Added the Esc:: part just because).

EDIT: HotkeyIts post just appeared... Different solution for the same problem. Very nice! Thanks Guys.
ste(phen|ve) kunkel
User avatar
tidbit
Posts: 1273
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Quick-entry date tool, feedback welcome.

23 Dec 2015, 19:00

just 2 days ago I made a date entry tool too!
http://i.imgur.com/8HNoBYX.png
7 presets and you can type your own. double-click the calendar to copy or press enter (or click the button).
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
kunkel321
Posts: 1194
Joined: 30 Nov 2015, 21:19

Re: Quick-entry date tool, feedback welcome.

23 Dec 2015, 19:11

@tidbit: Cool! Have you posted the code? I don't see it attached to your profile(?)
ste(phen|ve) kunkel
User avatar
kunkel321
Posts: 1194
Joined: 30 Nov 2015, 21:19

Re: Quick-entry date tool, feedback welcome.

23 Dec 2015, 19:14

Shadowpheonix wrote:
kunkel321 wrote:Actually, the DateSetter: label can go away altogether. :clap:
I left it because I thought it made a decent section separator/identifier for the code that follows it. :)
Technically-speaking, would it be better to have commented line e.g.
; ==== SEPARATOR =======
To separate the sections? Commented stuff gets ignored by AHK, so less strain on the system(?)
ste(phen|ve) kunkel
User avatar
tidbit
Posts: 1273
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Quick-entry date tool, feedback welcome.

23 Dec 2015, 19:18

nope, released it on IRC only (see the IRC link at top of the page). I might release here, no idea. It's just a simple gui and a button and formattime, pretty much. not worth a topic of its own, IMO.
without hijacking your topic, here's the link: http://pastebin.com/Czfyz6Mm
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
kunkel321
Posts: 1194
Joined: 30 Nov 2015, 21:19

Re: Quick-entry date tool, feedback welcome.

23 Dec 2015, 21:08

@tidbit: Nice! It also works as a way to preview what different date formats will look like. :) I've been envisioning a minimalistic GUI with a datepicker and a button for changing the last used date (possibly from OP script, above) by adding 3 years to it. I guess the date picker gui element and the stand alone date picker gui are essentially the same thing--yes?
ste(phen|ve) kunkel
User avatar
tidbit
Posts: 1273
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Quick-entry date tool, feedback welcome.

24 Dec 2015, 10:37

not sure why you mean by "date picker gui element" and "stand alone date picker gui"
the "gui, add, monthCal," is the big calender-like thing at the top of the gui.

"GUI with a datepicker and a button for changing the last used date (possibly from OP script, above) by adding 3 years to it"
should be mildly easy since you save the date in %OffSet% (I think). Just use envadd and guicontrol to set the moncal ahead 3 years.

get on irc and I could explain it better in real time without flooding your topic :P
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
kunkel321
Posts: 1194
Joined: 30 Nov 2015, 21:19

Re: Quick-entry date tool, feedback welcome.

24 Dec 2015, 10:59

Yea, I will check out the IRC thing.. .
I can ask general ahk questions too--yes?
I want to get the custom function figured out before working more on the gui.
ste(phen|ve) kunkel

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 152 guests