global open new tab in chrome

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jdfnnl
Posts: 14
Joined: 10 Mar 2022, 01:21

global open new tab in chrome

17 Mar 2024, 23:25

I would like to set 'ctrl + t' as a global hotkey for opening a tab in chrome whether or not the browser is the active window.
User avatar
mikeyww
Posts: 27162
Joined: 09 Sep 2014, 18:38

Re: global open new tab in chrome

18 Mar 2024, 07:03

Code: Select all

#Requires AutoHotkey v1.1.33.11
app      := "chrome.exe"
winTitle := "ahk_exe" app

$^t::
If !WinExist(winTitle) {
 Run % app
 SoundBeep 2500
 WinWait % winTitle,, 6
 If ErrorLevel {
  MsgBox 48, Error, An error occurred while waiting for the window.
  Return
 } Else Sleep 2000
}
WinActivate
Send ^t
SoundBeep 1500
Return
jdfnnl
Posts: 14
Joined: 10 Mar 2022, 01:21

Re: global open new tab in chrome

18 Mar 2024, 08:49

how can I fix this error?

Code: Select all

---------------------------
chrome tab.ahk
---------------------------
Error:  Missing "}"

	Line#
	010: Return
	011: if !WinExist(winTitle)  
	011: {
	012: Run,app
	013: SoundBeep,2500
	014: WinWait,winTitle,,6
	015: if ErrorLevel  
--->	015: {
	016: MsgBox,48,Error,An error occurred while waiting for the window.
	017: Exit
	018: Exit
	018: Exit

The program will exit.
---------------------------
OK   
---------------------------
gregster
Posts: 9079
Joined: 30 Sep 2013, 06:48

Re: global open new tab in chrome

18 Mar 2024, 08:53

Copy and use the complete code from the codebox in mikeyww's post, eg by pressing 'Select All' (or expanding/scrolling the codebox and selecting the whole code manually) before copying it.
jdfnnl
Posts: 14
Joined: 10 Mar 2022, 01:21

Re: global open new tab in chrome

18 Mar 2024, 10:06

Oh, silly mistake .. curious about the choice to add a beep?
User avatar
boiler
Posts: 17176
Joined: 21 Dec 2014, 02:44

Re: global open new tab in chrome

18 Mar 2024, 10:09

The good thing about such features is you can keep them if you like them and very easily remove them if you don't.
User avatar
mikeyww
Posts: 27162
Joined: 09 Sep 2014, 18:38

Re: global open new tab in chrome

18 Mar 2024, 10:18

I agree: delete if you wish!

Some of the rationale for beeps during testing or beyond is below.
  1. Confirms that a hotkey was triggered
  2. Confirms that something else is happening, such as while the user is waiting, or when no other action is visible
jdfnnl
Posts: 14
Joined: 10 Mar 2022, 01:21

Re: global open new tab in chrome

04 May 2024, 09:18

Would I be able to insert this script into a master script as written?
Works fine when run on its own, but when inserted into a collection of scripts,
I get this error message:
2024-05-04 07_14_28-Error.png
2024-05-04 07_14_28-Error.png (3.53 KiB) Viewed 693 times
User avatar
boiler
Posts: 17176
Joined: 21 Dec 2014, 02:44

Re: global open new tab in chrome

04 May 2024, 09:59

You can’t put the lines where it assigns the variables app and WinTitle below hotkeys when you combine scripts because they will never execute.
jdfnnl
Posts: 14
Joined: 10 Mar 2022, 01:21

Re: global open new tab in chrome

04 May 2024, 10:55

Thinking I will put this in a dedicated script as I am not sure how to avoid the conflict ..

Is there a way to put an exception in this script to disable this hotkey when photoshop is the active window?
User avatar
boiler
Posts: 17176
Joined: 21 Dec 2014, 02:44

Re: global open new tab in chrome

04 May 2024, 13:16

jdfnnl wrote: Thinking I will put this in a dedicated script as I am not sure how to avoid the conflict ..
I just explained how. Don't put the lines where it assigns those two variables below any hotkeys in your script. Put them at the very top of your combined script in the auto-execute section so that those lines will actually execute.

jdfnnl wrote: Is there a way to put an exception in this script to disable this hotkey when photoshop is the active window?
Put this line immediately above the line with the hotkey label:

Code: Select all

#If !WinActive("ahk_exe Photoshop.exe")

If you have any other hotkeys below that one in your script that you don't want affected by the above directive, place the following on a line preceding the first of those, assuming you don't already have other directives meant for them:

Code: Select all

#If

Explained: #If
User avatar
mikeyww
Posts: 27162
Joined: 09 Sep 2014, 18:38

Re: global open new tab in chrome

04 May 2024, 13:33

Below is just a way to combine these approaches.

Code: Select all

#If !WinActive("ahk_exe Photoshop.exe")
$^t::
If !WinExist(winTitle := "ahk_exe" app := "chrome.exe") {
 Run % app
 SoundBeep 2500
 WinWait % winTitle,, 6
 If ErrorLevel {
  MsgBox 48, Error, An error occurred while waiting for the window.
  Return
 } Else Sleep 2000
}
WinActivate
Send ^t
SoundBeep 1500
Return
#If

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 87 guests