add date function

This commit is contained in:
David Daily 2022-03-29 14:33:19 -05:00
parent e851dc5c3c
commit ab12192837

579
func.ahk
View File

@ -1,120 +1,501 @@
#SingleInstance force ; Only one instance at a time
SendMode, Input
FileEncoding, UTF-8 ; Makes sure the special characters dont break stuff
SetWorkingDir, %A_MyDocuments%\D3K ; Make sure we can find the .ahks linked below
#Include, func.ahk
d3k_version = 2.9 ; The current version
Menu, Tray, Icon, shell32.dll, 283 ; Set the tray icon to a keyboard
Menu, Tray, Add, Mouse Mover, Mouse_Mover ; Add item to the tray to move the mouse
Menu, Tray, Add, %A_AhkVersion%, docs
ini = %A_MyDocuments%\D3Ksettings.ini ; Where the settings ini is
;------------------------------------------------------------------------------
; Make sure the settings file exists, if not, create it
;------------------------------------------------------------------------------
GetDateTime(lang)
If !FileExist(ini) ; Check if the ini doesn't exist
{
UTCTimestamp := A_NowUTC ; Grab the current time and date
UTCFormatStr := "yyyy-MM-dd" ; The Date
FormatTime, DateStr, %UTCTimestamp%, %UTCFormatStr% ; format it to make it look like the Date we want
UTCFormatStr := "H:mm'Z'" ; The time
FormatTime, TimeStr, %UTCTimestamp%, %UTCFormatStr% ; Format the string to be better
if (lang = "en")
{
Return DateStr " at " TimeStr
}
if (lang = "de")
{
Return DateStr " um " TimeStr
}
if (lang = "ISO8601")
{
Return DateStr "T" TimeStr
}
if (lang = "date")
{
Return DateStr
}
}
GetInfo(xID)
{
if (xID)
{
File := FileOpen(A_MyDocuments "\emails.csv", "r")
Loop
{
Line := File.ReadLine()
Array := StrSplit(Line,",") ; split the line at its separating commas to get separate "columns" AKA elements
if InStr(Array[1], xID) ; if at the specified element (1) the specified content (dealers xID) has been found
{
Test := {xid: Array[1], email: Array[2], name: Array[3], user: Array[4], org: Array[5]} ; Return the array so we can do {variable}.email and so on
File.Close() ; Close the file
Return Test ; Return the array with the deets that we found
}
} Until (File.AtEOF)
File.Close()
Return false
}
if !(xID)
{
Return false
}
FileAppend,
(
; 0 is off, 1 is on
[USpec]
RACF=LF01234
Email=LastnameFirstname@JohnDeere.com
Name=Firstname
DocFile=Select File
[Main]
Mansol=1
MJDPaste=1
CaseFormatter=1
CFmail=0
[Replacement]
JDProductNames=1
GloVar=0
[Language]
German=0
), %ini%
Run Settings.ahk ; Runs the GUI for changing the settings, also accessible with Alt+Shift+\ (also easy way to restart this script)
}
;------------------------------------------------------------------------------
; INI Manipulation that supports UTF-8
; Read the ini
;------------------------------------------------------------------------------
; This is the part that reads the file to see what your settings are. Variables in the ini file are in all lowercase, variables here are CamelCase for more distinction
; User Specific things:
racf := ini_get(ini, "USpec", "RACF")
email := ini_get(ini, "USpec", "Email")
name := ini_get(ini, "USpec", "Name")
docfile := ini_get(ini, "USpec", "DocFile")
; General Settings
mansol := ini_get(ini, "Main", "Mansol")
supadmin := ini_get(ini, "Main", "Supadmin")
mjdpaste := ini_get(ini, "Main", "MJDPaste")
caseformatter := ini_get(ini, "Main", "CaseFormatter")
; Replacement
jdpn := ini_get(ini, "Replacement", "JDProductNames")
glovar := ini_get(ini, "Replacement", "GloVar")
; Language
ger := ini_get(ini, "Language", "German")
;------------------------------------------------------------------------------
; Global Variables
;------------------------------------------------------------------------------
ini_load(location)
If (glovar = 1)
{
File := FileOpen(location, "r")
out := {}
Loop
{
Line := File.ReadLine()
RegExMatch(Line, "(?<=\[).*(?=\])", _RESection) ; Matches section name
RegExMatch(Line, "(?<Key>.*)=(?<Value>.*)", _) ; Key = _Key, Value = _Value
glovarini := A_MyDocuments "\GloVar.ini" ; Location of the ini that the user modifies
If (_RESection)
glovarstart := "#SingleInstance force`n`n"
SetTimer, GloVar, 2000 ; Check every 2 seconds
GloVar:
WinWaitNotActive, GloVar.ini ; So that we don't get any problems with the file on disk being out of date. I use VSCode with the "Save on lose focus" option on, YMMV
{
_RESection := StrReplace(_RESection, " ", "_")
out[_RESection]:={}
currentSection := _RESection
FileGetTime, gvModNew, %glovarini%
if !(gvModNew = gvMod) ; Those two lines mean the rest of this only executes if there were changes to the ini.
{
gvMod := gvModNew
FileDelete, glovar.ahk ; Start with a clean slate
FileAppend, %glovarstart%, glovar.ahk ; makes sure we only have one instance of the script running at a time
RESection := "" ; Make sure that its clear
file := FileOpen(glovarini, "r")
Loop ; Read one line at a time
{
Line := file.ReadLine()
RegExMatch(Line, "(?<=\[).*(?=\])", RESection) ; explained above
RegExMatch(Line, "^(?<Key>.*)=(?<Value>.*)", RE) ; Key = REKey, Value = REValue
If !(RESection) ; If the RegEx doesn't find antything, its empty
{
If !(REValue) ; If there is no value for the key, skip it (Continue the loop at the next line)
{
Continue
}
If InStr(StoredSection, "Serial Numbers") ; If the section is "Serial Numbers", make everything uppercase
{
StringUpper, REValue, REValue ; Makes it uppercase
WinWaitNotActive, GloVar.ini ; Just to make sure
{
ini_write(glovarini, REKey, REValue)
FileGetTime, gvMod, %glovarini%
}
}
If InStr(REKey, "case") ; If a key contains "case". Case numbers are all in the format "LETTERS-NUMBERS".
{
StringUpper, REValue, REValue ; Makes it uppercase
RegExMatch(REValue, "(?<=\().*(?=\))", REMatch) ; Match everything but the parenthesis. When the case numbers are shown they have parenthesis, and those are annoying.
If (REMatch) ; If there's anything there
{
WinWaitNotActive, GloVar.ini
{
ini_write(glovarini, REKey, REMatch) ; Writes the properly formatted case number to glovar.ini
FileGetTime, gvMod, %glovarini%
}
REValue := REMatch
} Else {
If (_Value)
WinWaitNotActive, GloVar.ini
{
_Key := StrReplace(_Key, " ", "_")
out[currentSection][_Key] := _Value
ini_write(glovarini, REKey, REValue) ; Writes the properly formatted case number to glovar.ini
FileGetTime, gvMod, %glovarini%
}
}
} Until (File.AtEOF)
File.Close()
Return out
}
ini_get(location, inSec, inKey)
{
ini_loaded := {}
ini_loaded := ini_load(location)
inSec := StrReplace(inSec, " ", "_")
inKey := StrReplace(inKey, " ", "_")
needed := ini_loaded[inSec][inKey]
if (needed) ; Without this it doesn't know what to return and gets stuck
}
writethis := ":*:$" REKey "::" REValue "`n" ; Save the hotstring to a variable
FileAppend, %writethis%, glovar.ahk ; Write the variable to glovar.ahk
}
If (RESection) ; If we have a section
{
Return needed
} Else Return false
StoredSection := RESection
If InStr(RESection, "clear") ; Will clear the ini and save its and the documentation file's contents to a log
{
FileRead, doctemp, %docfile% ; Read documentation file, set in settings
FileRead, initemp, %glovarini% ; Read the ini
initemp := RegExReplace(initemp, "(?<=\[)clear(?=\])", "Info") ; Replace the "clear" section we set with Info
CurrTime := GetDateTime("en") ; get the current date and time as "YYYY-MM-DD at HH:MM GMT"
writethis := "Case on " . CurrTime . "`n`n`n" . doctemp . "`n`n" . initemp ; Save the current time, what was in the doc file, and glovarini to a variable
FileAppend, % "`n`n" writethis "`n`n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", %A_MyDocuments%/D3KLog.txt ; Write a few new lines , the content, and a line underneath
FileAppend,, temptemp
FileCopy, glovarsource, %glovarini%, 1 ; Copies and replaces any text in glovar.ini with the template
FileCopy, temptemp, %docfile%, 1 ; These two this close together makes it look like they get cleared at the same time
FileDelete, temptemp
fileread, gvMod, %glovarini% ; Make sure that this script knows what the ini was changed to so it doesn't constantly run through the above code
FileDelete, glovar.ahk ; THE CLEAN SLATE
FileAppend, %glovarstart%, glovar.ahk
Sleep, 500
FileGetTime, gvMod, %glovarini% ; Make sure that this script knows what the ini was changed to so it doesn't constantly run through the above code
If FileExist("glovar.ahk")
{
Run glovar.ahk
}
Return
}
}
} Until (file.AtEOF)
file.Close()
FileGetTime, gvMod, %glovarini% ; Make sure that this script knows what the ini was changed to so it doesn't constantly run through the above code
If FileExist("glovar.ahk")
{
Run glovar.ahk
ToolTip, glovar updated, 50, 50
Sleep, 500
ToolTip
}
}
}
Return
}
ini_write(location, inKey, inValue)
;------------------------------------------------------------------------------
; Settings window
;------------------------------------------------------------------------------
!+\::Run Settings.ahk ; Alt+Shift+\
Mouse_Mover:
Run, msmv.ahk
Return
;------------------------------------------------------------------------------
; DTAC Solution Opener
;------------------------------------------------------------------------------
#If, mansol = "1" ; checks from the variable thats set from the .ini file
!+S::Run Mansol_Opener.ahk ; Alt+Shift+S
#If ; these are to make sure one "if" doesn't influence the next accidentially
;------------------------------------------------------------------------------
; Case Formatter
;------------------------------------------------------------------------------
#If, CaseFormatter = "1"
Pause::Run Case_Formatter.ahk ; The Pause|Break key
#If
;-------------------------------------------------------------------------------
; Special Characters
;-------------------------------------------------------------------------------
#If, ger = "1"
; scharfes s / Eszett / ß
!s::Send {U+00DF} ;Alt+S
; ä
!a::Send {U+00E4} ;Alt+a
; ö
!o::Send {U+00F6} ;Alt+o
; ü
!u::Send {U+00FC} ;Alt+u
; Ä
+!A::Send {U+00C4} ;Alt+A
; Ö
+!O::Send {U+00D6} ;Alt+O
; Ü
+!U::Send {U+00DC} ;Alt+U
#If
;-------------------------------------------------------------------------------
; Capitalise dates
;-------------------------------------------------------------------------------
::monday::Monday
::tuesday::Tuesday
::wednesday::Wednesday
::thursday::Thursday
::friday::Friday
::saturday::Saturday
::sunday::Sunday
::january::January
::february::February
; ::march::March ; Commented out because it matches the common word "march".
::april::April
; ::may::May ; Commented out because it matches the common word "may".
::june::June
::july::July
::august::August
::september::September
::october::October
::november::November
::december::December
; German
#If, ger = "1"
::montag::Montag
::dienstag::Dienstag
::mittwoch::Mittwoch
::donnerstag::Donnerstag
::freitag:: Freitag
::samstag::Samstag
::sonntag::Sonntag
::januar::Januar
::februar::Februar
::märz::März
::mai::Mai
::juni::Juni
::juli::Juli
::oktober::Oktober
::dezebmer::Dezember
#If
;------------------------------------------------------------------------------
; Copypastas
;------------------------------------------------------------------------------
;STWA Applied
:*:]cms::
Send STWA applied{Enter 2}Status: Providing information{Enter 2}Comments:{Space}{Enter 2}Thank you,{Enter}%name%{Enter 2}Tier 2 internal steps:{Space}{Enter 2}SQL:{Enter}
Return
;------------------------------------------------------------------------------
; Email
;------------------------------------------------------------------------------
; Regular
:*:]email::
Send Hello,{Enter 2}{Space 3}
Return
; German
#If, ger = "1"
; Regular
:*:[email::
Send Hallo,{Enter 2}{Space 3}
Return
#If
;------------------------------------------------------------------------------
; Profile email paste
;------------------------------------------------------------------------------
; So when editing Profiles, it won't let you paste in the email field. We don't like that. Make sure to let go of all keys immediatley after pressing this
#If, mjdpaste = "1"
#v::
sleep, 750
Send %clipboard%
sleep, 500
send # ; to make sure the start menu isn't open for some reason
return
#If
;------------------------------------------------------------------------------
; Common Terms autocorrect and replacement
;------------------------------------------------------------------------------
#If, not(racf = "LF01234") ; So that it doesn't put the fake RACF from the default ini file
:*:]me::
Send, %racf%
return
:*:[me::
Send, %racf%
return
#If
#If, not(email = "LastnameFirstname@JohnDeere.com") ; Same as above
:*:@me::
Send, %email%
Return
#If
; JD Names
#If, jdpn = "1"
:*:[xx::XXXXXXXXXXXXX ; I'm not gonna try and find the right amount of X's to appease the CCMS demons
:*:]xx::XXXXXXXXXXXXX
; English
:*:]at::AutoTrac
:*:]sf::StarFire
:*:]jdld::JDLink Dashboard
:*:]jdlc::JDLink Connectivity
:*:]jdls::JDLink Subscription
:*:]jdll::JDLink
:*:]jdp::JDParts
:*:]mjd::MyJohnDeere
:*:]opsc::Operations Center
:*:]seccon::Section Control
:*:]gs::GreenStar
:*:]cc::CommandCenter
:*:]fc::Field Connect
:*:]rs::RowSense
:*:]sub::subscription
:*:]ss::Stellar Support
:*:]tman::Technical Manual
:*:]oman::Operator's Manual
:*:]hl3::HarvestLab 3000
:*:]hlo::Original HarvestLab
:*:]bin::Virtual Inventory
:*:]warrep::Warranty Reports
:*:]tcsm::Territory Customer Support Manager
:*:]macrep::Machine Reports
:*:]jdsm::John Deere Software Manager
:*:]jddm::John Deere Data Manager
:*:]serva::Service Advisor
:*:]muc::Master Unlock Code
:*:]asmn::Asset Manager
:*:]bsm::Base Station Manager
::rowsense::RowSense
:*:comar::COMAR
::mrtk::mRTK
::rda::RDA
::rtk::RTK
::autotrac::AutoTrac
:*:ccms::CCMS
:*:dtac::DTAC
::tcsm::TCSM
::itec::iTEC Pro
::ssu::SSU
::atu::ATU
:*:mtg::MTG
::wdt::WDT
::itc::iTC
:*:vin::Machine PIN ; Not actually vehicles, so they don't have VINs
::gs2::GS2
::gs3::GS3
::sf1::SF1
::sf2::SF2
::sf3::SF3
::sf4::SF4
::xid::xID
::pmcalc::PMCalc
::vat::VAT
:*:racf::RACF
::igrade::iGrade
:*:JDCP::JDCP
:*:ISOBUS::ISOBUS
; German
#If, ger = "1"
:*:[at::AutoTrac
:*:[sf::StarFire
:*:[jdlw::JDLink Web
:*:[jdld::JDLink Dashboard
:*:[jdl2::JDLink Dashboard 2.0
:*:[jdlc::JDLink Connectivity
:*:[jdls::JDLink Abonnement
:*:[jdll::JDLink
:*:[jdp::JDParts
:*:[mjd::MyJohnDeere
:*:[opsc::Einsatzzentrale
:*:[seccon::Teilbreitensteuerung
:*:[gs::GreenStar
:*:[cc::CommandCenter
:*:[fc::Field Connect
:*:[rs::RowSense
:*:[sub::Abonnement
:*:[ss::Stellar Support
:*:[tman::Technische Betriebsanleitung
:*:[oman::Betriebsanleitung
:*:[hl3::HarvestLab 3000
:*:[hlo::Originales HarvestLab
:*:[bin::Virtuellen Bestand
:*:[warrep::Warranty Reports
:*:[tp::TouchPoint
:*:[tcsm::Technischer Bezirksleiter
:*:[macrep::Machine Reports
:*:[jdsm::John Deere Software Manager
:*:[jddm::John Deere Data Manager
:*:[serva::Service Advisor
:*:[muc::Master Unlock Code
:*:[asmn::Asset Manager
:*:[bsm::Base Station Manager
#If
;------------------------------------------------------------------------------
; QoL Improvements
;------------------------------------------------------------------------------
#j:: ; Open the downloads folder on Win+J
Run, C:\Users\%racf%\Downloads
Return
#w:: ; Open My Documents folder on Win+W
Run, C:\Users\%racf%\Documents
Return
:*:[now:: ; Send the current time/date in ISO8601 format
:*:]now::
d_t := GetDateTime("ISO8601")
SendInput, %d_t%
Return
:*:[today:: ; Send the current date in ISO8601 format
:*:]today::
d_t := GetDateTime("date")
SendInput, %d_t%
Return
:*:[deg::{ASC 248}
:*:]deg::{ASC 248}
:*:[eq::{ASC 247}
:*:]eq::{ASC 247}
:*:[shrug::¯\_()_/¯
:*:]shrug::¯\_()_/¯
asciiart(art)
{
FileRead, tempini, %location%
needle := inKey . "=.*"
replacement := inKey . "=" . inValue
tempini := RegExReplace(tempini, needle, replacement,, 1)
tempini := RegExReplace(tempini, "\R+\R", "`r`n")
FileAppend, %tempini%, tempini ; Append the fixed ini to a new file
FileCopy, tempini, %location%, 1 ; Copy the file over, overwriting existing contents
FileDelete, tempini ; Delete the fixed temporary ini
For index, value in art
{
SendInput, %value%{ShiftDown}{Enter}{ShiftUp}
}
Return
}
:*:]yee::
art := ["░░░░░░░░░░░░░▄███▄▄▄░░░░░░░","░░░░░░░░░▄▄▄██▀▀▀▀███▄░░░░░","░░░░░░░▄▀▀░░░░░░░░░░░▀█░░░░","░░░░▄▄▀░░░░░░░░░░░░░░░▀█░░░","░░░█░░░░░▀▄░░▄▀░░░░░░░░█░░░","░░░▐██▄░░▀▄▀▀▄▀░░▄██▀░▐▌░░░","░░░█▀█░▀░░░▀▀░░░▀░█▀░░▐▌░░░","░░░█░░▀▐░░░░░░░░▌▀░░░░░█░░░","░░░█░░░░░░░░░░░░░░░░░░░█░░░","░░░░█░░▀▄░░░░▄▀░░░░░░░░█░░░","░░░░█░░░░░░░░░░░▄▄░░░░█░░░░","░░░░░█▀██▀▀▀▀██▀░░░░░░█░░░░","░░░░░█░░▀████▀░░░░░░░█░░░░░","░░░░░░█░░░░░░░░░░░░▄█░░░░░░","░░░░░░░██░░░░░█▄▄▀▀░█░░░░░░","░░░░░░░░▀▀█▀▀▀▀░░░░░░█░░░░░", "yee ░░░░░█░░░░░░░░░░░░█░░░░"]
asciiart(art)
Return
:*:]glass::
art := ["▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄", "█░░░░░░░░▀█▄▀▄▀██████░▀█▄▀▄▀██████░", "░░░░░░░░░░░▀█▄█▄███▀░░░▀██▄█▄███▀░"]
asciiart(art)
Return
docs:
run https://www.autohotkey.com/docs/AutoHotkey.htm
Return