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)