Script to activate all active/running applications.

I know how to do this for any specific application. However I would like to adapt it to bring all active/running applications to the foreground. I mean here the ones the user uses, not the stuff that runs in the background like “SoftwareUpdateNotificationManager” - “QuickLookUIService” etc.

Does anybody know how to adapt this script? Or am I running in the wrong direction?

tell application "System Events"
	set ids to bundle identifier of every application process
	if ids contains "com.apple.Mail" then 
		tell application "Mail" to activate 
	else
		return "Not running"
	end if
end tell 

thanks folks.

Well… only one application can be frontmost/ in the foreground, so it’s not clear what you’re trying to achieve.
But you can get the visible (non-background) apps:

tell application "System Events"
	set ids to bundle identifier of every application process whose visible is true
end tell

That what you were after?

Thanks first of and yes you are correct.

Well it does not what I want to do. I want to have all active applications to display itself on the desktop. so if they have windows open I like to have those all visible. and yes I understand they be stacked behind one and other.

am I clear here? hope so.

Yes, all windows of all visible apps will be on the desktop, and overlapping each other. Do you want them to be all visible next to one another? That’s a seriously complicated goal to achieve with AppleScript.
Doesn’t hitting F3 show, more or less, what you want to see? If you are looking for a way to get to one specific window, that would work just fine, I think.

FWIW, I read your posts multiple times and it is not clear to me what you want to do.

peavine, I try again.

Lets say 5 apps have open windows and are ‘hiding’ and/or if you like their windows are hiding. (Command H would do this).

Now I want to bring all of the 5 apps in one go back in sight. So undo the Command H so to say for all 5. Now all the open aps are active and their windows on top of each other so to speak.

That is what I like the script for.

Hopefully I am clear.

alastor933 thanks.

fine.

OK did not realise this.

Nope.

A-ha! You want to unhide apps! Then Google this site for “unhide”, and you’ll find this.

Edit: in case you don’t know - type this in a Google search box to search only MacScripter:

Here is a script which drops a lot of processes but some unwanted ones remain.

tell application "System Events"
	set allProps to properties of application processes
	set theApplications to {}
	repeat with aProps in allProps
		if ((path of file of aProps) contains ":Applications:") and (role of aProps is "AXApplication") then set end of theApplications to {name of aProps, id of aProps}
	end repeat
	
	-- "FinderSyncExt", "popCalendar", "Box", "SMARTReporter", "FastScripts", "fake_mojave", "Box UI" would be dropped but I don't find which property would identify them
	-- Of course I may use a list of exceptions as below but at dislike this scheme.
	
	set theApplications2 to {}
	repeat with aProps in allProps
		if name of aProps is not in {"FinderSyncExt", "popCalendar", "Box", "SMARTReporter", "FastScripts", "fake_mojave", "Box UI"} then
			if ((path of file of aProps) contains ":Applications:") and (role of aProps is "AXApplication") then set end of theApplications2 to {name of aProps, id of aProps}
		end if
	end repeat
	{theApplications, linefeed, linefeed, theApplications2}
end tell
(*
{{{"FinderSyncExt", 86037}, {"popCalendar", 114716}, {"Box", 131104}, {"SMARTReporter", 135201}, {"FastScripts", 143395}, {"TextEdit", 147492}, {"fake_mojave", 151589}, {"Box UI", 188462}, {"Safari", 200753}, {"firefox", 258111}, {"EasyFind", 421991}, {"Script Editor", 426088}, {"Preview", 491640}, {"Pages", 635035}, {"Numbers", 680102}, {"Mail", 733363}, {"Activity Monitor", 811206}, {"Pages", 905437}}, "
", "
", {{"TextEdit", 147492}, {"Safari", 200753}, {"firefox", 258111}, {"EasyFind", 421991}, {"Script Editor", 426088}, {"Preview", 491640}, {"Pages", 635035}, {"Numbers", 680102}, {"Mail", 733363}, {"Activity Monitor", 811206}, {"Pages", 905437}}}
*)

Of course, I may use brute force and drop processes belonging to a predefined list but I dislike this scheme.

Don’t worry, when I ran it, Pages 4.3 ans Pages 8.1 were loaded.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 15 juin 2020 17:19:04

aha, so simple eh? Thanks.

I looked a lot this morning but never found anything.

Thanks Yvan very useful.

That is very clear. The following script will unhide hidden apps.

tell application "System Events" to set visible of (every process whose background only is false and visible is false) to true

However, it does not rearrange windows in every instance as you apparently want. Some time ago I wrote a script that cascades the windows of the active app:

https://macscripter.net/viewtopic.php?id=47419

It would be easy to write a script that unhides hidden apps then cascades the apps’ windows but this would not work well. Perhaps the simple script above will work for you or perhaps another forum member has a better approach.

peavine it works, thanks.