Skip to content

Instantly share code, notes, and snippets.

@davebrny
Created December 15, 2017 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davebrny/e5a67ee5550b06bd267ccd9082ec6295 to your computer and use it in GitHub Desktop.
Save davebrny/e5a67ee5550b06bd267ccd9082ec6295 to your computer and use it in GitHub Desktop.
(autohotkey) - open a local file or folder from dynalist
#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
*/
@davebrny
Copy link
Author

davebrny commented Dec 15, 2017

usage

  • use alt + c to get selected files from file explorer
  • add the file or folder path to dynalist
  • click on the item or note, then use alt + r

the first file path that is found in the text will be run. if there is more than 1 file then select/highlight the one you want before using the hotkey

@kennethaar
Copy link

Thank you. Works like magic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment