Open a pdf file in Chrome New tab

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
w_i_k_i_d
Posts: 11
Joined: 17 Apr 2024, 16:28

Open a pdf file in Chrome New tab

Post by w_i_k_i_d » 17 Apr 2024, 16:37

Hello

Trying to :-

1. Select a file (with mouse)
2. Press a key (RAlt + l)
3. Open it in already open chrome and in a new tab.

So I have : (from google searches etc)

Code: Select all

>!l::  			;;  RAlt + L
{
    Var := % Explorer_GetSelection()                
	Run "C:\Program Files\Google\Chrome\Application\chrome.exe /newtab" %Var%
Return
}

Thanks


[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

[Mod action: Topic moved from "Ask for Help (v2)" since this is v1 code.]
[Mod action: Moved topic back to v2 help since this seems to be a translation request.]

User avatar
V0RT3X
Posts: 243
Joined: 20 May 2023, 21:59
Contact:

Re: Open a pdf file in Chrome New tab

Post by V0RT3X » 17 Apr 2024, 17:17

I would lose the brackets...

Code: Select all

>!l::  			;;  RAlt + L
    Var := % Explorer_GetSelection()                
	Run "C:\Program Files\Google\Chrome\Application\chrome.exe /newtab" %Var%
Return

You will also need the Explorer_GetSelection() function for this if you don't already have it. Looks to be a version of this old script possibly?
https://www.autohotkey.com/board/topic/100983-how-can-we-retrieve-the-name-of-a-file-selected/

w_i_k_i_d
Posts: 11
Joined: 17 Apr 2024, 16:28

Re: Open a pdf file in Chrome New tab

Post by w_i_k_i_d » 17 Apr 2024, 18:19

I was pretty sure I posted this in AHK 2.0 section

[Mod action: Topic moved from "Ask for Help (v2)" since this is v1 code.] :shock:

Can I please get this script for AHK 2.0
Thanks

gregster
Posts: 9085
Joined: 30 Sep 2013, 06:48

Re: Open a pdf file in Chrome New tab

Post by gregster » 17 Apr 2024, 18:25

w_i_k_i_d wrote:
17 Apr 2024, 18:19
I was pretty sure I posted this in AHK 2.0 section

[Mod action: Topic moved from "Ask for Help (v2)" since this is v1 code.] :shock:

Can I please get this script for AHK 2.0
I moved the topic back to v2 help.
Generally, if you post v1 code and want it translated to v2, it would be good to state this in the original post since most people - and especially new forum users - who post v1 code in the v2 help subforum are doing that erroneously.

User avatar
mikeyww
Posts: 27188
Joined: 09 Sep 2014, 18:38

Re: Open a pdf file in Chrome New tab

Post by mikeyww » 18 Apr 2024, 06:07

Code: Select all

; This script opens selected files in the Chrome Web browser
#Requires AutoHotkey v2.0

#HotIf WinActive('ahk_class CabinetWClass') && WinExist('ahk_exe chrome.exe')
>!l:: {
 SoundBeep 1500
 For item in Explorer_GetSelection() {
  Run 'chrome.exe ' item
  Sleep 500
 }
}
#HotIf

Explorer_GetSelection() {
 ; Adapted: https://www.autohotkey.com/boards/viewtopic.php?style=17&t=60403#p255256 by teadrinker
 ; https://www.autohotkey.com/boards/viewtopic.php?p=509080#p509080
 hwnd := WinExist('A'), selection := []
 If WinGetClass() ~= '(Cabinet|Explore)WClass'
  For window in ComObject('Shell.Application').Windows {
   Try window.hwnd
   Catch
    Return
   If window.hwnd = hwnd
    For item in window.document.SelectedItems
     selection.Push(item.Path)
  }
 Return selection
}

w_i_k_i_d
Posts: 11
Joined: 17 Apr 2024, 16:28

Re: Open a pdf file in Chrome New tab

Post by w_i_k_i_d » 19 Apr 2024, 15:24

Thanks Mikeyww

Giving this a try :D
I heard the beep, which is amazing to hear

System can't find Chrome.exe
replaces that with "C:\Program Files\Google\Chrome\Application\chrome.exe"
still can't find it

w_i_k_i_d
Posts: 11
Joined: 17 Apr 2024, 16:28

Re: Open a pdf file in Chrome New tab

Post by w_i_k_i_d » 19 Apr 2024, 15:47

Changed it back to Mikeyww's script 'chrome.exe'
and somehow I don't get that error anymore from AHK reload but
instead a small popup window opened like the one for Open With saying:-

"You will need a new app to open chrome.exec" (notice the 'c' at the end)
'Look for an app in Microsoft store'
'Always use this app'

And I'm pretty sure Chrome is not in Microsoft app store.

(please see attached screenshots)

Also I would like to learn this language Mikeyww
Is it C## Cbash ?
Attachments
0072.jpg
(13.04 KiB) Downloaded 42 times
0071.jpg
(34.01 KiB) Downloaded 42 times
0070.jpg
(30.74 KiB) Downloaded 42 times

User avatar
boiler
Posts: 17195
Joined: 21 Dec 2014, 02:44

Re: Open a pdf file in Chrome New tab

Post by boiler » 19 Apr 2024, 16:06

Notice the difference between the two MsgBox displays and why, and look at the difference between mikeyww's code and what the error message shows for your code.

Code: Select all

#Requires AutoHotkey v2.0
item := 'c'
MsgBox 'chrome.exe' item
MsgBox 'chrome.exe ' item

w_i_k_i_d
Posts: 11
Joined: 17 Apr 2024, 16:28

Re: Open a pdf file in Chrome New tab

Post by w_i_k_i_d » 19 Apr 2024, 16:17

That space did wonders :D
It works ! Its alive !
Thank you so much

Post Reply

Return to “Ask for Help (v2)”