Is There Any Way to Send a Key Combo to an App in the Background?

I use Xcode all the time to build an internal mac app.

When I run the app it will launch. Come to the foreground and then Xcode will go to the background.

All this is correct behavior.

Xcode has a debug console that can be seen while my app is in the front.

It gets messy. The key combo to clear it is Command K.

I would love to create a KM macro that I can call with key combo that would "send" COMMAND K to Xcode which would be in the background at that point.

Does anyone know if this is possible?

thx.

I'm not sure about sending a hotkey - but I believe if there is a corresponding menu item for that then you can call it on an app in the background.

Unfortunately I think focus will switch to Finder but this might not be the case for every command so you might want to try it with Xcode if there's a corresponding menu item to clear the console.

Yes, you can do this.

Although it's not guaranteed to work in every app. You'll have to experiment and find out if it will work as desired in Xcode.

2 Likes

the first pass did not work. it seems this command requires Xcode to have focus.

I will experiment more this afternoon. but thank you! I did not even know one could send keys to other apps.

I added a "switch to application Xcode" and then "switch to last application" to switch back to my mac app and it did work.

So focus seems to be the issue.

The switch back and forth happened so fast that I guess I am ok with this.

Thank you for your help. I will report back if I discover a method that does not require Xcode to be in the forefront.

1 Like