Window will not be automatically created when app is to be shown and its window is closed

I am currently using an app called Manico to implement app switching, and it works very well, but I am trying to use BTT to replace it.

So I created some keyboard shortcuts using BTT, and used the "Show / Hide Specific Application" option to achieve my goal, but I found a problem, when the application window is closed, BTT does not automatically create a window when using the shortcut to switch applications.

What I want to achieve is that when I switch the app to show, if the app is not running, it will be launched. If the app is running but the window is closed, it automatically creates a window (equivalent to clicking the app icon in the Dock bar).

I tried to use the "Send CMD+N, if No Open Windows" option, but it has two problems. When I check this option.

  1. If the app does not support CMD+N to create new window, BTT will not automatically create window for me when I show / hide the app, I need to click the app icon on the dock with mouse to do it. For example, the Mail app.

  2. If the application supports CMD+N to create new window, two windows will be created when the application is launched. For example, iTerm2.

How can I achieve my goal in BTT? Any suggestions? Thank you.

If you just want the "click dock icon" behavior, I think the "Launch Application" action should work fine:

Thank you. I am now using the following script to achieve my goal. I'm not very familiar with Apple Script, but it works.

set appName to "My Application"

tell application appName
	if it is not running then
		activate
	else
		tell application "System Events"
			set activeApp to name of first application process whose frontmost is true
			if visible of application process appName is false or (not (exists (window 1 of process appName))) or (appName is not in activeApp) then
				tell process "Dock"
					tell UI element appName of list 1
						click
					end tell
				end tell
				set visible of application process appName to true
			else
				set visible of application process appName to false
			end if
		end tell
	end if
end tell
1 Like