feed clicked link to program

Get help with using AutoHotkey and its commands and hotkeys
lom
Posts: 4
Joined: 31 Jul 2020, 20:55

feed clicked link to program

31 Jul 2020, 21:15

I want to be able to click a link in a browser (while holding a button / button combo) and feed it as a program parameter (in my case, mpv player).

I think I know how to get the link:

Code: Select all

#NoEnv, #Persistent, #SingleInstance
LButton::
  Send {Rbutton}{down 5}{Enter}
return
but I don't know how to then feed it to mpv (`mpv <link>` inside Powershell / cmd).
lom
Posts: 4
Joined: 31 Jul 2020, 20:55

Re: feed clicked link to program

31 Jul 2020, 21:36

I might've figured it out:

Code: Select all

#NoEnv, #Persistent, #SingleInstance
~z & LButton::
  Send {Rbutton}{down 5}{Enter}
  Run, O:\bin\mpv\mpv.exe %clipboard%
return
z being there so I could click links with normal behavior and ~ being there so I could actually use the z key as.. the z key. It doesn't seem particularly efficient, so if anyone's got a better way, I'd be really grateful
gregster
Posts: 4917
Joined: 30 Sep 2013, 06:48

Re: feed clicked link to program

01 Aug 2020, 04:51

As a side note, this won't work:

Code: Select all

#NoEnv, #Persistent, #SingleInstance
Everything after #NoEnv (which will work) will be ignored, afaik.
This would be okay:

Code: Select all

#NoEnv 
#Persistent
#SingleInstance
lom
Posts: 4
Joined: 31 Jul 2020, 20:55

Re: feed clicked link to program

01 Aug 2020, 15:02

I see. Thanks for the headsup! I just saw someone recommend putting that line at the beginning of every script, so here I am, blindly doing just that.
gregster
Posts: 4917
Joined: 30 Sep 2013, 06:48

Re: feed clicked link to program

01 Aug 2020, 15:08

In your specific case, it actually shouldn't make any difference, since scripts which contain hotkeys are automatically persistent and single-instance ;) .
But generally, it shouldn't work... and will silently fail.
lom
Posts: 4
Joined: 31 Jul 2020, 20:55

Re: feed clicked link to program

05 Aug 2020, 17:37

Slightly better version (I think):

Code: Select all

#NoEnv
#Persistent
#SingleInstance

#IfWinActive ahk_exe firefox.exe
~z & LButton::
  Send {Rbutton}
  Sleep 10
  Send {down 5}
  Sleep 10
  Send {Enter}
  Sleep 10
  Run, O:\bin\mpv\mpv.exe ""%clipboard%""
return
#IfWinActive
Seems to work a bit more consistently with the delays, isn't active outside desired program (in this case, Firefox) and accepts special characters (e.g. ? or & if the video you clicked is a part of a playlist) thanks to double quotes.

Return to “Ask For Help”

Who is online

Users browsing this forum: Dario91, Google [Bot], Milenko, nichatr, TAC109 and 32 guests