-
-
Save jasondavis/cd2467b118eda4d953446e5de653be71 to your computer and use it in GitHub Desktop.
π§ββοΈ (autohotkey) - one click image download
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
[hotkeys] | |
!p = C:\Users\%a_userName%\Pictures\.i.mages | |
[browser] | |
ahk_exe chrome.exe | |
ahk_exe firefox.exe | |
ahk_exe iexplore.exe | |
ahk_exe vivaldi.exe | |
[settings] | |
image_formats = jpg,png,gif | |
spells = alakazam!,sim sala bim!,abracadabra!,shazam! | |
[script info] | |
version = 0.3 | |
description = one click image download | |
author = davebrny | |
source = https://gist.github.com/davebrny/1cf149ffd9ced3792389c609a69f5db5 | |
*/ | |
#noEnv | |
#persistent | |
#singleInstance, force | |
; set hotkeys & folders | |
iniRead, section_text, % a_lineFile, hotkeys | |
loop, parse, % section_text, `n, `r | |
{ | |
stringGetPos, pos, a_loopField, =, L1 | |
stringMid, this_hotkey, a_loopField, pos, , L | |
stringMid, this_folder, a_loopField, pos + 2 | |
hotkey, ifWinActive, ahk_group browser | |
hotkey, % this_hotkey, i_mage_hotkey | |
asc := asc_convert(this_hotkey) | |
hk_%asc% := this_folder | |
} | |
iniRead, spells, % a_lineFile, settings, spells | |
global spell := [] | |
loop, parse, spells, `, | |
spell.insertAt(1, a_loopfield) | |
; create browser group | |
iniRead, section_text, % a_lineFile, browser | |
loop, parse, % section_text, `n, `r | |
groupAdd, browser, % a_loopfield | |
return ; end of auto-execute --------------------------------------------------- | |
i_mage_hotkey: | |
hotkey_name := "hk_" asc_convert(a_thisHotkey) | |
folder := %hotkey_name% ; get folder stored in hotkey name | |
i_mage(folder) | |
return | |
i_mage(folder) { | |
restore_cb := clipboard | |
clipboard := "" | |
winGet, process_name, processName, a | |
splitPath, process_name, , , , process_name ; without extension | |
if isLabel(process_name "_browser") | |
goSub, % process_name "_browser" | |
image_url := clipboard | |
clipboard := restore_cb | |
if (image_url = "") | |
msg("mage says no...") | |
else | |
{ | |
folder := variable_replace(folder) | |
filename := prep_filename(image_url) | |
if fileExist(folder "\" filename) | |
msg("""" filename """ `n`nhas already been saved") | |
else | |
{ | |
msg("saving image...", "30000") | |
if !fileExist(folder) | |
fileCreateDir, % folder | |
urlDownloadToFile, % image_url, % folder "\" filename | |
msg(cast_spell() "`nimage saved") | |
} | |
} | |
} | |
variable_replace(string) { | |
for this, that in {"%a_desktop%":a_desktop, "%a_myDocuments%":a_myDocuments | |
, "%a_scriptDir%":a_scriptDir, "%a_userName%":a_userName} | |
stringReplace, string, string, % this, % that, all | |
return string | |
} | |
prep_filename(url) { | |
splitPath, % url, filename | |
filename := regExReplace(filename, "[\Q*""\:/?<>|\E]") ; remove \/:*?"<>| | |
; remove everything after .jpg | |
iniRead, image_formats, % a_lineFile, settings, image_formats | |
loop, parse, image_formats, `, | |
{ | |
if inStr(filename, "." a_loopField) | |
{ | |
stringGetPos, pos, filename, % "." a_loopField, R1 | |
stringMid, filename, filename, pos + 1 + strLen(a_loopField), , L | |
break | |
} | |
} | |
return filename | |
} | |
asc_convert(hotkey) { | |
loop, parse, % hotkey | |
asc .= (asc ? "_" : "") . asc(a_loopfield) | |
return asc | |
} | |
msg(msg, msg_time="2500") { | |
toolTip, % msg | |
setTimer, msg_timer, % msg_time | |
} | |
cast_spell() { | |
static last_number | |
loop, | |
random, number, 1, % spell.maxIndex() | |
until (number != last_number) | |
last_number := number | |
return spell[number] | |
} | |
msg_timer(){ | |
setTimer, msg_timer, off | |
toolTip, | |
} | |
; --------------------------------------- | |
chrome_browser: | |
firefox_browser: | |
vivaldi_browser: | |
mouseClick, right | |
sleep 60 | |
send {o} | |
clipWait, 1 | |
return | |
iexplore_browser: | |
mouseClick, right | |
sleep 60 | |
send {c} | |
clipWait, 1 | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment