Created
December 15, 2017 17:43
-
-
Save davebrny/e5a67ee5550b06bd267ccd9082ec6295 to your computer and use it in GitHub Desktop.
(autohotkey) - open a local file or folder from dynalist
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
#noEnv | |
#singleInstance, force | |
sendMode input | |
setTitleMatchMode, 2 | |
; create window groups | |
groupAdd, dynalist, ahk_exe Dynalist.exe ; desktop app | |
groupAdd, dynalist, - Dynalist ahk_exe vivaldi.exe ; browsers | |
groupAdd, dynalist, - Dynalist ahk_exe chrome.exe | |
groupAdd, dynalist, - Dynalist ahk_exe firefox.exe | |
groupAdd, dynalist, - Dynalist Microsoft Edge ahk_exe ApplicationFrameHost.exe | |
; set hotkeys | |
hotkey, ifWinActive, ahk_class CabinetWClass ; file explorer | |
hotkey, !c, get_file | |
hotkey, ifWinActive, ahk_group dynalist | |
hotkey, !r, run_file | |
return ; end of auto-execute --------------------------------------------------- | |
get_file: | |
selected := get_selected_files() | |
if (selected) | |
{ | |
clipboard := selected | |
msg(selected) | |
} | |
return | |
run_file: | |
selected := get_selected_text() | |
if (selected = "") | |
{ | |
send ^{a} | |
selected := get_selected_text() | |
} | |
path := get_path_from_text(selected) | |
if fileExist(path) | |
run, % path | |
else | |
{ | |
send {right} ; unselect text | |
msg("computer says no") | |
} | |
return | |
get_selected_files() { | |
for window in comObjCreate("shell.application").windows | |
selected := window.document.selectedItems | |
for file in selected | |
file_list .= (file_list ? "`n" : "") . file.path | |
return file_list | |
} | |
get_selected_text() { | |
save_clipboard := clipboardAll | |
clipboard := "" | |
send ^{c} | |
clipWait, 0.3 | |
selected_text := trim(clipboard) | |
clipboard := save_clipboard | |
return selected_text | |
} | |
get_path_from_text(string) { | |
loop, parse, string, `n, `r | |
{ | |
strReplace(a_loopField, a_space, "", space_count) | |
loop, % space_count + 1 | |
{ | |
stringGetPos, pos, % a_space . a_loopField, % a_space, % "L" a_index | |
stringMid, string, % a_space . a_loopField, pos + 2 | |
strReplace(string, a_space, "", space_count_b) | |
loop, % space_count_b + 1 | |
{ | |
stringGetPos, pos, % string . a_space, % a_space, % "R" a_index | |
stringMid, string_b, % string . a_space, pos, , L | |
if fileExist(string_b) | |
return trim(string_b) | |
} | |
} | |
} | |
} | |
msg(msg) { | |
toolTip, % msg | |
setTimer, msg_timer, 2000 | |
} | |
msg_timer(){ | |
setTimer, msg_timer, off | |
toolTip, | |
} | |
/* | |
[script info] | |
version = 0.1 | |
description = open a local file or folder from dynalist | |
author = davebrny | |
source = https://gist.github.com/davebrny/e5a67ee5550b06bd267ccd9082ec6295 | |
*/ |
Thank you. Works like magic!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage