A New Hotstring Trick and Converting Dates in Documents into DateTime Stamps (Coming Soon!)

Making a List of Future Blogs While Sequestered

ProgrammingRobotRight now, the massive book of motley AutoHotkey tips consumes the vast majority of my time. Therefore, I have less blogging time. However, I don’t want my lack of blogs to make anyone think I sit idle. In the course of the current task at hand, I’ve accumulated even more topics which I need to blog about:

  • I’ve changed the format of the TalkingText.ahk script since AutoHotkey version 1.1.28 (February 2018) introduced single-line action Hotstrings using the option X. I was able to reduce the code by calling a function:
:xb0z*:horse::AnimalSounds("horse")
:xb0z*:cow::AnimalSounds("cow")
:xb0z*:train::AnimalSounds("train")
:xb0z*:bird::AnimalSounds("nature2")
:xb0z*:hand::AnimalSounds("applause")
:xb0z*:bear::AnimalSounds("bear_growl_y")
:xb0z*:cat::AnimalSounds("cat_meow_x")
:xb0z*:dog::AnimalSounds("dog_bark_x")
:xb0z*:owl::AnimalSounds("owl")
:xb0z*:pig::AnimalSounds("pig")
:xb0z*:lamb::AnimalSounds("sheep521")

AnimalSounds(animal)
{
  Sleep 1000
  SoundPlay, Sounds/%animal%.wav
}

This used to be impossible.

  • I figured out how to convert dates selected in documents into DateTime stamps for use in other scripts (such as HowLongYearsMonthsDays.ahk):
^!#d::
  OldClipboard:= ClipboardAll
  Clipboard:= ""
  Send, ^c ;copies selected text
  ClipWait 0
  If ErrorLevel
  {
    MsgBox, No Text Selected!
    Return
  }


If (RegExMatch(Clipboard,"([[:alpha:]]+).*?(\d\d?).*?(\d\d\d?\d?)" 
     , Date))
{
  MonthConvert(Date1)
  If NewMonth = "Not found!"
  {
    MsgBox Not a valid date!
    Return
  }
  If strlen(Date3) = 2
    Date3 := YearCheck(Date3)
  DateStamp := Date3 . NewMonth . Format("{:02}", Date2)
  If DateStamp is not Date
  {
    MsgBox Invalid date!
    Return
  }
  MsgBox, % "Date Stamp:`r" . DateStamp
}
Else If (RegExMatch(Clipboard, "(\d\d?).*?(\d\d?).*?(\d\d\d?\d?)" 
     , Date))
{
  If strlen(Date3) = 2
    Date3 := YearCheck(Date3)
  DateStamp := Date3 . Format("{:02}", Date1) . Format("{:02}", Date2)
  If DateStamp is not Date
  {
    MsgBox Invalid date!
    Return
  }
  MsgBox, % "Date Stamp:`r" . DateStamp
}
Else
  MsgBox No date found!

Clipboard := OldClipboard

Return

MonthConvert(month)
{
Global NewMonth
NewMonth := InStr(month, "jan") ? "01"
: InStr(month, "feb") ? "02"
: InStr(month, "mar") ? "03"
: InStr(month, "apr") ? "04"
: InStr(month, "may") ? "05"
: InStr(month, "jun") ? "06"
: InStr(month, "jul") ? "07"
: InStr(month, "aug") ? "08"
: InStr(month, "sep") ? "09"
: InStr(month, "oct") ? "10"
: InStr(month, "nov") ? "11"
: InStr(month, "dec") ? "12"
:"Not found!"
}

YearCheck(Year)
{
If Year > 40
Year := "19" . Year
Else
Year := "20" . Year
Return Year
}

Only American date formats for now, but an easy fix for European dates. Merely, switch the RegEx to look for months second and make other adjustments accordingly.

  • The Secret Index in the AutoHotkey site started up again. (Don’t know when?) That means my earlier work on an AutoHotkey Quick Reference script operates again. Go figure.

In the future, I plan to address these and other topics in more depth, but, for now, I must immerse myself in working on this tome of AutoHotkey tips.

jack

This post was proofread by Grammarly
(Any other mistakes are all mine.)

(Full disclosure: If you sign up for a free Grammarly account, I get 20¢. I use the spelling/grammar checking service all the time, but, then again, I write a lot more than most people. I recommend Grammarly because it works and it’s free.)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s