Can you?: Change current app with another via a pop up menu? + Questions


I was wondering if it is possible to use BTT to allow the user to change a current app with another app (either active or minimized) and have it take the same window size and placement on the screen via a pop-up menu with a search function?

I asked on Reddit about this, and people said it is possible; however, I can't seem to wrap my head around it.

Key features I'm looking for:

  • Switch the current app with another.
  • Via a menu with window preview and search.
  • Ability to switch the left and right apps around.

Also is it possible to create magnetic windows similar to when you have two apps side by side on windows and when you change the width of one app the other adapt with it?

The best I've got it is the following:

  • BTT > Keyboard Shortcuts > New Action
  • Hot Key: CMD+Shift+A
  • Run Apple Script (Blocking)
-- AppleScript to prompt for app selection from currently running apps and switch window position

-- Get the list of running applications
tell application "System Events"
    set runningApps to (name of every application process where background only is false)
end tell

-- Prompt user to choose an application
set chosenApp to (choose from list runningApps with prompt "Select an application to switch to:")

if chosenApp is false then
end if

set chosenApp to item 1 of chosenApp

-- Get the current frontmost application's window bounds
tell application "System Events"
    set frontApp to first application process whose frontmost is true
    set frontWindow to first window of frontApp
    set {xPos, yPos, width, height} to position & size of frontWindow
end tell

-- Activate the chosen application
tell application chosenApp to activate

-- Wait a moment for the application to open
delay 1

-- Resize and reposition the new application's window
tell application "System Events"
    set newApp to first application process whose name is chosenApp
    set newWindow to first window of newApp
    set position of newWindow to {xPos, yPos}
    set size of newWindow to {width, height}
end tell

But outside of a pop up window nothing happens.