-
-
Save davebrny/6746782dc720820cd61a552f470fe9cf to your computer and use it in GitHub Desktop.
/* | |
[folders] | |
folder_1= | |
folder_2= | |
folder_3= | |
[settings] | |
prefix = LS_ | |
time_format = yyyyMMddhhmmss | |
fullscreen_hotkey = | |
upload_hotkey = | |
[script info] | |
version = 0.4.3 | |
lightshot = 5.4.0.1 | |
description = improvements for lightshot (app.prntscr.com) | |
author = davebrny | |
source = https://gist.github.com/davebrny/6746782dc720820cd61a552f470fe9cf | |
*/ | |
#noEnv | |
#singleInstance, force | |
#installKeybdHook | |
sendMode, input | |
process, priority, , high | |
loop, HKLM, SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList, 1, 1 ; get user SID | |
{ | |
if (a_loopRegName = "ProfileImagePath") | |
{ | |
regRead, output | |
if inStr(output, a_userName) | |
{ | |
stringReplace, user_sid, a_loopRegSubKey, SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\ | |
break | |
} | |
} | |
} | |
lightshot_subkey := user_sid . "\Software\SkillBrains\Lightshot" | |
iniRead, prefix, % a_lineFile, settings, prefix | |
iniRead, time_format, % a_lineFile, settings, time_format | |
iniRead, custom_menu, % a_lineFile, settings, custom_menu | |
iniRead, fullscreen, % a_lineFile, settings, fullscreen_hotkey | |
iniRead, upload, % a_lineFile, settings, upload_hotkey | |
if (fullscreen) ; make hotkeys pass through to lightshot | |
hotkey, ~%fullscreen%, rename_with_date | |
if (upload) | |
hotkey, ~%upload%, rename_with_date | |
gui +lastFound | |
dllCall("RegisterShellHookWindow", UInt, winExist()) ; code from SKAN | |
onMessage(dllCall("RegisterWindowMessage", Str, "SHELLHOOK"), "shellMessage") | |
return ; end of auto-execute ------------------------------------------------ | |
#if winActive("ahk_exe Lightshot.exe", , "Save As") | |
l:: | |
; rButton:: | |
goSub, custom_menu | |
return | |
#if winActive("ahk_exe Lightshot.exe", , "Save As") | |
enter:: | |
$^s:: | |
send ^{s} | |
goSub, rename_with_date | |
return | |
#if | |
rename_with_date: | |
sleep 700 ; wait for file to appear to | |
file_ext := file_ext() | |
loop, files, % save_folder() "\Screenshot_*" . file_ext | |
{ | |
formatTime, formatted_time, % a_loopFileTimeModified, % time_format | |
fileMove, % a_loopFileFullPath, % save_folder "\" prefix . formatted_time . file_ext | |
} | |
return | |
file_ext() { | |
global lightshot_subkey | |
regRead, dword, HKU, % lightshot_subkey, Format | |
file_format := (dword = "1") ? "png" : (dword = "2" ? "jpg" : "bmp") | |
return "." file_format | |
} | |
save_folder() { | |
global | |
if (save_folder = "") | |
{ | |
regRead, save_folder, HKU, % lightshot_subkey, LastSavedDir | |
if (save_folder = "") | |
save_folder := a_myDocuments "\Lightshot" | |
} | |
return save_folder | |
} | |
shellMessage(wParam, lParam) { | |
global ls_id | |
If (wParam = 1) ; HSHELL_WINDOWCREATED | |
{ | |
winGet, process_name, ProcessName, % "ahk_id " ls_id := lParam | |
if (process_name = "Lightshot.exe") | |
setTimer, set_edit_text, 100 | |
} | |
} | |
set_edit_text: | |
if winExist("Save As ahk_exe Lightshot.exe") | |
{ | |
setTimer, set_edit_text, off | |
formatTime, formatted_time, % a_now, % time_format | |
controlSetText, edit1, % prefix . formatted_time . file_ext(), ahk_class #32770 | |
winWaitClose, Save As ahk_exe Lightshot.exe | |
goSub, rename_with_date ; rename any other 'screenshot_1.png' files | |
save_folder := "" | |
setTimer, set_edit_text, on | |
} | |
if !winExist("ahk_id " ls_id) | |
setTimer, set_edit_text, off | |
return | |
custom_menu: ; right click menu | |
menu, lightshot, useErrorLevel | |
regRead, keep_selection, HKU, % lightshot_subkey, KeepSelection | |
regRead, capture_cursor, HKU, % lightshot_subkey, CaptureCursor | |
save_folder := save_folder() | |
if (save_folder) | |
{ | |
stringGetPos, pos, save_folder, \, R2 | |
stringMid, parent_folder, save_folder, % pos + 1 | |
menu, folder_menu, add, % save_folder, set_folder | |
menu, folder_menu, disable, % save_folder | |
menu, folder_menu, add | |
} | |
folders_created := "" | |
loop, | |
{ | |
iniRead, folder, % a_lineFile, folders, folder_%a_index% | |
if (fileExist(folder)) and (folder != save_folder) | |
{ | |
menu, folder_menu, add, % folder, set_folder | |
++folders_created | |
} | |
} | |
until (folder = "ERROR") | |
if (folders_created) | |
menu, folder_menu, add | |
menu, folder_menu, add, Add New Folder, add_folder | |
menu, lightshot, add, Upload to prntscr.com %a_tab% Ctrl+D, menu_ctrl | |
menu, lightshot, add, Print %a_tab% Ctrl+P, menu_ctrl | |
menu, lightshot, add, Copy %a_tab% Ctrl+C, menu_ctrl | |
menu, lightshot, add, Save %a_tab% Ctrl+S, menu_ctrl | |
menu, lightshot, add, Select Full Screen %a_tab% Ctrl+A, menu_ctrl | |
menu, lightshot, add, Clear selection , menu_clear | |
menu, lightshot, add, Cancel %a_tab% Esc, menu_esc | |
menu, lightshot, add | |
menu, lightshot, add, Settings: , menu_close | |
menu, lightshot, add | |
menu, lightshot, add, Remember Selection , keep_selection | |
menu, lightshot, add, Capture Cursor , capture_cursor | |
menu, lightshot, add | |
if (save_folder) | |
menu, lightshot, add, %parent_folder% , menu_close | |
menu, lightshot, add, Folders , :folder_menu | |
menu, lightshot, add | |
menu, lightshot, add, Close this menu , menu_close | |
menu, lightshot, disable, Settings: | |
menu, lightshot, disable, %parent_folder% | |
menu, lightshot, % (keep_selection ? "check" : "unCheck"), Remember Selection | |
menu, lightshot, % (capture_cursor ? "check" : "unCheck"), Capture Cursor | |
menu, lightshot, show | |
menu, lightshot, delete | |
menu, folder_menu, delete | |
goSub, rename_with_date ; check for new screenshots | |
return | |
menu_ctrl: | |
letter := subStr(a_thisMenuItem, 0, 1) | |
send % "^{" format("{:L}", letter) "}" | |
return | |
menu_clear: | |
send {rButton}{down 6} ; select from original menu | |
sleep 50 | |
send {enter} | |
return | |
menu_esc: | |
send {esc} | |
return | |
capture_cursor: | |
new_value := (capture_cursor = 0) ? 1 : 0 | |
regWrite, REG_DWORD, HKU, % lightshot_subkey, CaptureCursor, % new_value | |
return | |
keep_selection: | |
new_value := (keep_selection = 0) ? 1 : 0 | |
regWrite, REG_DWORD, HKU, % lightshot_subkey, KeepSelection, % new_value | |
return | |
menu_close: | |
return | |
set_folder: | |
regWrite, REG_SZ, HKU, % lightshot_subkey, LastSavedDir, % a_thisMenuItem | |
return | |
add_folder: | |
send {esc} | |
fileSelectFolder, new_folder, *%save_folder% | |
if (new_folder) | |
{ | |
loop, | |
{ | |
iniRead, folder, % a_lineFile, folders, folder_%a_index% | |
if (folder = "") or (folder = "ERROR") | |
iniWrite, % " " new_folder, % a_lineFile, folders, folder_%a_index% | |
} | |
until (folder = "") or (folder = "ERROR") or (new_folder = folder) | |
} | |
return |
Hi thanks, wonderful improvement, could you please explain how can i use this file to enhance the features.
Hi thanks, wonderful improvement, could you please explain how can I use this file to enhance the features.
You need to AutoHotkey program in order to launch script
@davebrny Cool script, however, capturing a cursor doesn't work :(
@davebrny Cool script, however, capturing a cursor doesn't work :(
i havnt been using lightshot for a while now but this script just toggles the registry setting for that option
fantastic work, this really overcomes most of lighshot's weaknesses in terms of functionality
@ditdivdotdot i stopped using lightshot a few years ago now but im taking it that they still havnt fixed the "screenshot_1" naming problem? thats sad if true, but im glad to hear this script is still of some use to someone!
@davebrny nope they still haven't fixed that "screenshot_1" naming problem unfortunately
Thanks for this script. This work perfectly but unfortunately there's some errors.
- Enter button didn't work
- File named Screenshot_x.png when using
ctrl+s
instead of enter coz this button didn't work
Could you fix this? Thank you in advance. :)
lightshot+
date filenames
lightshot saves files as 'screenshot_1, screenshot_2' etc which doesnt work well in most cases since changing the save folder to another one that already contains a 'screenshot_1' file means you will get the 'file already exists' warning and have to manually rename it.
this script renames files with a date instead to avoid this problem. the default is "LS_20171115084024.png" but the format can easily be modified to something more readable by adding punctuation:
^!+#p
(ctrl + alt + shift + windows + p)enter to save
when the screenshot selection window is open you can use the enter key (instead of the default ctrl + s) to quickly save the screenshot to the last folder location without opening up the 'save as' dialog
custom menu
use the
L
key when at the screenshot selection window to show a custom menu with the following options:favourite folders
multiple folders can be added to the ini section at the top of the file.
to set one of these folders as the default save location, select it from the 'folders' list in the custom menu