Mrrrr
AdMiN
Inregistrat: acum 17 ani
Postari: 2228
|
|
All credits go to davebrny,
Comment by davebrny, and usage:
this only works on browsers and images where you can right click an image and press a key to select the "copy image url" menu item
USAGE:
- hover the cursor over an image - press alt + p to have the image automagically downloaded
hotkeys and folders different folders and their corresponding hotkeys can be set in the ini section at the top of the file. the format is hotkey = folder
the following variables can used in the folder path: - a_desktop - a_myDocuments - a_scriptDir - a_userName
supported browsers - chrome - firefox - internet explorer - vivaldi
to add another browser, add the exe process name of the browser to the ini section (line 5, after [browser]) and then put the instructions to get the image url at the end of the script. (or add the details to a comment below and ill update the script)
See comment at the end of this gist:
/* [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 = */
#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 |
_______________________________________
|
|