From 748e3ab321f730d346e6211ba57c54d2187aa0a3 Mon Sep 17 00:00:00 2001 From: David Daily Date: Wed, 8 Jul 2026 11:54:28 -0500 Subject: [PATCH] update to AHK v2 --- func.ahk | 153 ++++++++++++++++--------------------------------------- 1 file changed, 44 insertions(+), 109 deletions(-) diff --git a/func.ahk b/func.ahk index 73151fa..cec7aef 100644 --- a/func.ahk +++ b/func.ahk @@ -1,62 +1,11 @@ -#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 -SetTitleMatchMode, 2 +#Requires AutoHotkey v2 ; v2 only +#SingleInstance force ; Only one instance at a time +FileEncoding("UTF-8") ; Makes sure the special characters dont break stuff +SetWorkingDir(A_MyDocuments "\D3K") ; Make sure we can find the .ahks linked below +SetTitleMatchMode(2) -d3k_version := 3 ; The current version +global d3k_version := 3 ; The current version -GetDateTime(lang) -{ - FormatStr := "yyyy-MM-dd" ; The Date - FormatTime, DateStr, %A_NowUTC%, %FormatStr% ; format it to make it look like the Date we want - FormatStr := "H:mm'Z'" ; The time - FormatTime, TimeStr, %A_NowUTC%, %FormatStr% ; 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 - } -} ;------------------------------------------------------------------------------ ; INI Manipulation that supports UTF-8 @@ -64,49 +13,48 @@ GetInfo(xID) ini_load(location) { - out := {} - File := FileOpen(location, "r") - cleaner := File.Read() - File.Close() + temp := FileOpen(location, "r") + cleaner := temp.Read() + temp.Close() cleaner := RegExReplace(cleaner, "`am)^[\s\R]*") ; Remove empty lines cleaner := RegExReplace(cleaner, "m)[ \t]+$") ; Get rid of extra space at the end of values (NEEDS FIXED) - File := FileOpen(location, "w") - File.Write(cleaner) - File.Close() - File := FileOpen(location, "r") + temp := FileOpen(location, "w") + temp.Write(cleaner) + temp.Close() + temp := FileOpen(location, "r") + out := Object() Loop { - Line := File.ReadLine() - RegExMatch(Line, "(?
(?<=\[).*(?=\]))|(?.*)=(?.*)", r) ; Key = rKey, Value = rValue, Section = rSection - If (rSection) + Line := temp.ReadLine() + RegExMatch(Line, "(?
(?<=\[).*(?=\]))|(?.*)=(?.*)", &r) ; Key = r.Key, Value = r.Value, Section = r.Section + If (r.Section) { - rSection := Trim(rSection, " `t`r`n") ; Remove pesky newlines and extra space - rSection := StrReplace(rSection, " ", "§") ; AHK can't handle spaces in nested array names, so they're substituted with § - out[rSection]:={} - c_Section := rSection + out.%r.Section% := Map() + current_Section := r.Section } Else { - rKey := Trim(rKey, " `t`r`n") - rValue := Trim(rValue, " `t`r`n") - out[c_Section, rKey] := rValue + trimKey := Trim(r.Key, " `t`r`n") + trimValue := Trim(r.Value, " `t`r`n") + out.%current_Section%[trimKey] := trimValue } - } Until (File.AtEOF) - File.Close() + } Until (temp.AtEOF) + temp.Close() Return out } ini_write(location, inKey, inValue) ; Don't need to specify section because you can only have one hotstring anyway { - Critical, On - file := FileOpen(location, "r") - temp := file.Read() - file.Close() - inKeyReg := "(?<=^" inKey "=)\S*" ; Regex to make sure we're matching only the value for the requested key + Critical("On") + ini := FileOpen(location, "r") + temp := ini.Read() + ini.Close() + inKeyReg := "(?<=" inKey "=)\S*" ; Regex to make sure we're matching only the value for the requested key temp := RegExReplace(temp, inKeyReg, inValue) - file := FileOpen(location, "w") - file.Write(temp) - file.Close() + ini := FileOpen(location, "w") + ini.Write(temp) + ini.Close() + Critical("Off") } @@ -117,52 +65,39 @@ sett_ini := A_MyDocuments "\D3Ksettings.ini" ; Where the settings ini is If !FileExist(sett_ini) ; Check if the sett_ini doesn't exist { - file := FileOpen(sett_ini, "w") + ini := FileOpen(sett_ini, "w") writethis := " ( LTrim [USpec] 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 )" - file.Write(writethis) + ini.Write(writethis) file.Close() - Run Settings.ahk ; Runs the GUI for changing the settings, accessible with Alt+Shift+\ (also easy way to restart this script) + Run("Settings.ahk") ; Runs the GUI for changing the settings, accessible with Alt+Shift+\ (also easy way to restart this script) } ;------------------------------------------------------------------------------ ; Read the sett_ini ;------------------------------------------------------------------------------ -; This is the part that reads the file to see what your settings are. Variables in the sett_ini file are in all CamelCase, variables here are lowercase for more distinction +; This is the part that reads the file to see what your settings are. -settings := {} -settings := ini_load(sett_ini) +global settings := ini_load(sett_ini) +; started as global variables, keeping this commented out in case there's some old script where I need to replace something ; User Specific things: -email := settings["USpec", "Email"] -name := settings["USpec", "Name"] -docfile := settings["USpec", "DocFile"] - -; General Settings -mansol := settings["Main", "Mansol"] -supadmin := settings["Main", "Supadmin"] -mjdpaste := settings["Main", "MJDPaste"] -caseformatter := settings["Main", "CaseFormatter"] -cfmail := settings["Main", "CFmail"] +;global email := settings.USpec["Email"] +;global docfile := settings.USpec["DocFile"] ; Replacement -jdpn := settings["Replacement", "JDProductNames"] -glovar := settings["Replacement", "GloVar"] +;global jdpn := settings.Replacement["JDProductNames"] +;global glovar := settings.Replacement["GloVar"] ; Language -ger := settings["Language", "German"] \ No newline at end of file +;global ger := settings.Language["German"] \ No newline at end of file