'Getting device ID for custom configuration in Android Studio

In Android Studio I can have different configurations and I can choose on which device I want to run them.

I want to run certain adb commands (like adb reverse) before running the app, is there a way to get the selected device ID as a macro to pass it to the command?

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source