"List of Running Apps"

I would like to get a list of of running apps that are not running in background.

This list of apps would show the same apps that I can see when I press cmd+tab.

So, instead of getting all processes (get_string_variable "running_processes") something like (get_string_variable "running_foreground_apps").

Thanks!

you can use this internal function:

let apps = await BTTActions.copyLaunchedApplicationsInFrontToBackOrder();

Which is e.g. used here:

1 Like

You can run this shell command (or the AppleScript inside by itself):

osascript -e 'tell application "System Events" to get name of every process whose visible is true'

Edit: See Andreas' answer above, it's more simple.

1 Like

How do I use that internal function inside an applescript?

that is not possible unfortunately, if you need something similar in apple script, have a look at @fortred2 's answer

I prefer to not use system events inside the applescript.

Is it possible to save the list of apps in a BTT variable using the internal function you proposed?

That would be possible. Or maybe you could use JS to get the info you need and then call apple script from within that JS?

The function mentioned returns an array with objects like these:

That array would be perfect to be stored in a BTT string variable.

I would need to configure it like this:

2 triggers: when a frontmost app quits or opens
1 action: store in a BTT string variable the array you posted

how i do that??? :grinning:


async function someJavaScriptFunction() {
let apps = await BTTActions.copyLaunchedApplicationsInFrontToBackOrder();

let appsString = JSON.stringify(apps);

await set_string_variable({variableName: "something", to: appsString});
		
}

However that array can be huge. You should probably filter it for your needs before saving it to a variable.

What are you trying to achieve?

Thanks for your help, Andreas!

It's true that the array I get is a little bit crazy. I would prefer to have a new advanced condition with the list of foreground apps, if it's feasable.

What I am trying to achieve is:

  • know when there is only one app in foreground (Finder)
  • know when four apps (Finder,Totalmix,Cubase,Pages) are running without any other app running

@Andreas_Hegenberg your method copyLaunchedApplicationsInFrontToBackOrder is quite fast. I'd like to retrieve the same info in a thrid party app outside of BTT, but with AppleScript it is far slower (when trying to get all fields of apps and windows). Can you explain how you do it behind the scene? AppleScript? Swift?