Skip to content

Instantly share code, notes, and snippets.

@davebrny
Last active March 14, 2022 14:03
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davebrny/dea8b041f3d3ac3faeb9d915163c0ba3 to your computer and use it in GitHub Desktop.
Save davebrny/dea8b041f3d3ac3faeb9d915163c0ba3 to your computer and use it in GitHub Desktop.
(autohotkey) - launch files/folders/urls from a text list
#noEnv
#singleInstance, force
sendMode, input
return
!l:: goSub, get_text_to_launch
!+l::goSub, text_launcher ; repeat last selection
get_text_to_launch:
clipboard_save := clipboardAll
clipboard := ""
send ^{c} ; check for selected text
clipWait, 0.3
if (clipboard = "") ; if nothing was selected, then select all
{
send ^{a}^{c}
clipWait, 0.3
send {right} ; deselect text
}
selected_text := clipboard
clipboard := clipboard_save
goSub, text_launcher
return
text_launcher:
menu, tl_menu, add, % t := "text launcher", run_line
menu, tl_menu, default, % t
menu, tl_menu, disable, % t
menu, tl_menu, add
; create menu
loop, parse, selected_text, `n, `r
{
if a_loopField is space
continue
line := trim(a_loopField)
if fileExist("C:\Users\" a_userName . line)
line := "C:\Users\" a_userName . line ; convert "\Documents\file.txt" to full path
quoted_path := subStr(line, 2, strLen(line) - 2) ; catch paths with quotes on either side
if fileExist(quoted_path)
line := quoted_path
; if url, folder or file
if regExMatch(line, "http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+")
or instr(fileExist(line), "D")
or fileExist(line)
menu, tl_menu, add, % line, run_line
}
menu, tl_menu, show
menu, tl_menu, delete
return
run_line:
run, % a_thisMenuItem
return
/*
[script info]
version = 1.0
description = launch files/folders/urls from a text list
author = davebrny
source = https://gist.github.com/davebrny/dea8b041f3d3ac3faeb9d915163c0ba3
*/
@davebrny
Copy link
Author

davebrny commented Sep 11, 2019

usage

  • select the text you want to launch
    • if no text is select then ctrl+a will be used to select all the text
  • press alt + L to show the menu
  • use altshift + L to re-use the last menu without needing to select anything

paths in your user folder can be added like this: \Documents\file.txt
full paths can also have quotes on either side "C:\Users\dave\Documents\file.txt"

@doesn123
Copy link

Hi there,

I can't quite get my head around this script.
I see that files/folders/urls are added to a menu with the hotkey - but what purpose does this serve?
Do I need to add paths to text documents within the script?

Please enlighten me ;)

@davebrny
Copy link
Author

Hi there,

I can't quite get my head around this script.
I see that files/folders/urls are added to a menu with the hotkey - but what purpose does this serve?
Do I need to add paths to text documents within the script?

Please enlighten me ;)

hey. yea i didnt explain it too well :D the idea was that you just highlight text anywhere in windows (text you might get from an email, on a website, in a txt file etc) and if there were any url's or files/folders in the text, they would show in the list and be launch-able.

usually url's in an email would be clickable anyway so this is not needed as much, but if someone sent you 10 urls this would be useful since you could highlight the text once, then use the alt+shift hotkey to bring up the same menu, instead of having to switch back to your email app 10 times

@doesn123
Copy link

that explains it!
thanks very much :)

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