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:
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.
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.
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:
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?
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}'
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. @Macs_Productivity, 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.
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!
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.
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.