How to make a Python window take focus after launching it?

How can I make a Python window take focus after launching it?

I think you are confusing actions which work on applications with actions which work on windows. Applications and windows are different things that both have a focus. I think the action you are using affects which window is put up front whereas there’s a separate action which determines which application goes to the front.

Look up the activate application action. That may solve it.

I cannot get this to work:

I see two possible problems (but I don't use python, so you may need someone else to help you.)

  1. Your first action launches a command line version of python, which I will assume (but could be wrong) does not launch a GUI, which means your third action is unrelated to your first action. I'm guessing that your third action launches a GUI environment for python, which is a completely separate process from your command line compiler. So I'm puzzled what you expect your macro to do.

  2. Your first action launches "python3" while your third action activates "python". The latter is either a GUI, or could be version 2 of python, since version 2 is usually called "python."

I really don't know if either of my ideas is correct. You probably need to clarify how you installed both apps. I think they are separate apps. If so, neither app likely knows much about the other, and it will be up to you to find a way to get the two apps to work together.

1 Like

Python is a scripting language, it doesn't have windows. Python Launcher is just a launcher for Python scripts, they don't run "in" that app.

AFAIK the default for Python Launcher is to run scripts in Terminal. If the script has/creates a GUI then "the window" will belong to whatever creates that window -- in macOS I think you have to bundle the script and UI stuff into an app, so it'll be that app you have to activate.

But you may not even be getting that far. Depending on your Python script you may be stuck at the "Execute Shell Script" action since that isn't set to asynchronous -- the macro will pause there, waiting for a returned value, which may not come until the Python script has finished. You can test that by putting a "Display" action immediately after the "Shell" action -- does the "Display" happen while your Python script/app is still open?

1 Like