one-liners to restore built-in variables

Post your working scripts, libraries and tools
User avatar
davebrny
Posts: 83
Joined: 05 Dec 2016, 06:26

one-liners to restore built-in variables

05 Jul 2019, 07:45

i made a function a while back to save the state of a built-in variable, change it while youre running something else, then set it back to what it was... but i never really used it much in the end since i share a lot of my scripts and if i used the function then it would mean other people would also have to have to download it and put it in their Lib folder

so i figured out a way to save and set a variable on a single line so it ends up doing the same thing just without having any dependencies

Code: Select all

autoTrim, % ("off"), restore_at := a_autoTrim
autoTrim, % restore_at

setBatchLines, % (-1), restore_bl := a_batchLines
setBatchLines, % restore_bl

setControlDelay, % (-1), restore_cd := a_controlDelay
setControlDelay, % restore_cd

coordMode, caret, % ("client"), restore_cmc := a_coordModeCaret
coordMode, caret, % restore_cmc

coordMode, mouse, % ("client"), restore_cmme := a_coordModeMenu
coordMode, mouse, % restore_cmme

coordMode, mouse, % ("client"), restore_cmm := a_coordModeMouse
coordMode, mouse, % restore_cmm

coordMode, pixel, % ("client"), restore_cmp := a_coordModePixel
coordMode, pixel, % restore_cmp

coordMode, toolTip, % ("client"), restore_cmtt := a_coordModeToolTip
coordMode, toolTip, % restore_cmtt

setDefaultMouseSpeed, % (0), restore_dms := a_defaultMouseSpeed
setDefaultMouseSpeed, % restore_dms

detectHiddenText, % ("on"), restore_dht := a_detectHiddenText
detectHiddenText, % restore_dht

detectHiddenWindows, % ("on"), restore_dhw := a_detectHiddenWindows
detectHiddenWindows, % restore_dhw

isCritical, % ("off"), restore_ic := a_isCritical
isCritical, % restore_ic

sendMode, % ("input"), restore_sm := a_sendMode
sendMode, % restore_sm

stringCaseSense, % ("on"), restore_scs := a_stringCaseSense
stringCaseSense, % restore_scs

setTitleMatchMode, % (2), restore_tmm := a_titleMatchMode
setTitleMatchMode, % restore_tmm

setTitleMatchMode, % ("slow"), restore_tmms := a_titleMatchModeSpeed
setTitleMatchMode, % restore_tmms

setWinDelay, % (-1), restore_wde := a_winDelay
setWinDelay, % restore_wde

setWorkingDir, % (a_scriptDir), restore_wd := a_workingDir
setWorkingDir, % restore_wd
here is an example of one of them in use

Code: Select all

detectHiddenWindows, % ("on"), restore_dhw := a_detectHiddenWindows
winGet, running, list, ahk_class AutoHotkey
loop % running
    {
    winGetTitle, title, % "ahk_id " running%a_index%
    script_path := regExReplace(title, "\s-\sAutoHotkey\s.*")
    path_list .= (path_list = "" ? "":"`n") . script_path
    }
detectHiddenWindows, % restore_dhw
msgBox, % path_list

and heres a small script i made so they can be quickly added whenever you need them.
ctrl+alt + b to show the menu. the first line is pasted and the second is added to the clipboard so you can paste it further down yourself

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 41 guests