Launch app from before_app_launch

Hi,

In a config, I’d like to launch a simple app popup window from inside the execute method of the before_app_launch hook.

Here’s the scenario:
When the BeforeAppLaunch execute function is running, I am checking to see if the DCC app that is being launched is already running. If it is, I want to launch my custom app that displays a dialog window. (I used the tk-multi-starterapp to build my dialog panel.)

In testing my app dialog panel, it runs via a Shotgun toolkit menu command and also via a tk-shell command. However, I can’t quite figure out how to access and run it from within the before_app_launch execute function.

Is this possible - can I somehow import my app and run it from before_app_launch? If not, what would I need to change to use it there?

Thanks for any help,
Rich

2 Likes

Hi Rich

Welcome to the forums!!

So to start with you could launch your app via the before_app_launch.py hook with the following code.

# launch the publish app
engine = self.parent.engine
engine.execute_in_main_thread(engine.commands["Publish..."]["callback"])
# to see all the available commands, print `engine.commands`

This in itself wont make it blocking. However you can use the engine.show_modal in your app to display your window in a blocking way.

Using the starter app as an example you would change this line:

To be show_modal rather than shot_dialog. This will prevent it from continuing with the before_app_launch.py hook until the window is closed.

Best
Phil

2 Likes

Thanks, Phil!

That opens up a whole new world of ideas. I did not know it was that simple to run any of the registered app commands!

I needed only two lines:

engine = self.parent.engine
engine.execute_in_main_thread(engine.commands['Illustrator Task Start']['callback'])

Brilliant.

Rich

4 Likes