Shell script to return list of all apps in Applications folder

I would like to create a shell script action to return a list of all applications names in the /Applications folder (and subfolders, e.g. Photoshop appears in /Applications/Adobe Photoshop 2022/Adobe Photoshop 2022.app)

So far, I have found the following command, which returns output like shown in the partial screenshot below:

find -E /Applications -regex '.*.app'

Ideally, (assuming this is the full output) the script would return:

Adobe Acrobat
Keyboard Maestro
Mocha AE
Adobe After Effects Render Engine 2022
Adobe After Effects 2022

Note that if an output line has /Applications/example1.app/example2.app, only example1 should be returned.

Thanks for your help!

Not fully tested, but how about:

mdfind -onlyin /Applications "kind:application" | awk -F '/' '{print $NF}'

...and you could pipe the results through sort and uniq if that helps.

There may be better ways to do this, depending on what you are trying to achieve.

1 Like

It's problematic to do this with 'find' in the shell, because the shell does not recognize packages on the macOS - it simply sees them as directories. There are ways to work around that, but it gets complicated.

@Nige_S' example using 'mdfind' is going to be the simplest means of getting the data you want.

The other most effective way of doing this is to use Applescript Objective-C, which does allow you to prevent descent into macOS packages.

1 Like

Are you dead set on using a shell script? I ask because a few months ago I wrote a quick macro to compile a list of installed apps using native Keyboard Maestro actions... I could share if you were interested.

1 Like

An alternative to trawling through the file-system for file-names which match a string pattern might be to explore the options of the pkgutil shell command.

For a listing of installed applications, identified by bundle id, for example:

pkgutil --pkgs

For other options:

man pkgutil

To define a general listing of the names of package-installed applications, the macro below embeds a call to pkgutil --pkgs in a JavaScript which obtains and sorts application names:

1 Like

Sure, please share!

Excellent!

Only one issue: it looks like "Universal" applications do not appear in the output; for instance, the default Notes app. Is there a way to include these as well?

image

If you look closely at the screenshot you'll see the path to most "default" Apple apps is now /System/Applications (Safari appears to be the exception). So if you want to include those you'll need to search there as well.

Or just search everywhere with mdfind "kind:application" | awk -F '/' '{print $NF}'

2 Likes

If you only want a list of all apps in the Applications folder (original question) you can open the Applications folder, do a select all and then paste into a text document. Nice and easy!

A little too easy -- what about the apps in eg /Applications/Utilities?

As so often, it's perhaps worth taking a step back before going forward. @Bobby_Joe, why do you want a list of apps in the Applications folder (and not, for example, those installed in the user-space)? The why will inform the output you need, which might suggest a particular approach.

1 Like

I suppose I don't only want the ones in the /Applications folder.
mdfind "kind:application" | awk -F '/' '{print $NF}' | sort | uniq -i ended up being right for me.
I appreciate your help!

I'm interested in the differences between the mdfind and pkgutil approaches. On my computer,

mdfind 'kind:application' | awk -F '/' '{print $NF}' | sort -fu | wc -l

returns 405, while

pkgutil --pkgs | sort -fu | wc -l

returns only 158. A huge difference!

Given that the Finder says I have 123 items in /Applications and 17 in /Applications/Utilities, I was leaning toward pkgutil being more accurate until I noticed that maccatalyst.com.atebits.Tweetie2 was in the list generated by pkgutil. Tweetie 2 was a nice app, but it's never been on this M1 MacBook Air, so I'm guessing pkgutil is picking up old installation info that was copied onto this computer. And it doesn't seem to include any of the apps that come with macOS.

2 Likes

pkgutil is miles out on my machine -- for example, 32 different entries for acrobat and zero for the rest of Creative Cloud. OTOH, using mdfind for all apps is rather too complete for most purposes, including apps in System Frameworks, registered printers, the 35 "bundled" apps within the Parallels Toolbox app, etc. system_profiler SPApplicationsDataType is similarly, but not quite as, extensive.

I don't think there's "one true way" to do this -- it'll depend on what you want to report and, almost certainly, will require considerable finessing of either the search path(s) or the results returned.

Under normal circumstances I would not do this, because it will return apps from all sorts of unexpected places including external drives.

I would be more selective of the search locations:

mdfind -onlyin /Applications -onlyin /System/Applications/ "kind:application"

Unless of course I really did want to find every app on the system.

:sunglasses:

-Chris

1 Like

From what I see Rob's macro is only listing packages in the root of the /Applications folder.

The man page formulation for pkgutil suggests a subset defined by a particular installation history:

provides access to the “receipt” database used by the Installer

Not if you omit the onlyin option, which I did.

pkgutil doesn't support -onlyin, so I don't know what you're talking about...