It seems that System_profiler missed some applications. Right or wrong

Sometimes ago I discovered that the application darktable was not reported by the instruction :
do shell script “system_profiler SPApplicationsDataType”

As I am curious I wrote a script to list every applications available in my Applications folder which are not reported by the shell script.

Here it is.

----------------------------------------------------------------
use AppleScript version "2.5"
use framework "Foundation"
use script "FileManagerLib" version "2.2.2"
use scripting additions
----------------------------------------------------------------
script o
	property reportedApps : {}
	property missedApps : {}
	property fullList : {}
	property thePaths : {}
end script

my germaine()

on germaine()
	set startTime to (time of (current date))
	# List files available in Applications Folder
	set posixPath to POSIX path of (path to applications folder)
	set o's thePaths to objects of posixPath result type paths list with searching subfolders without include folders and include invisible items
	
	set fullReport to do shell script "system_profiler SPApplicationsDataType"
	set o's fullList to rest of (my splitString:fullReport usingString:"Location: ")
	
	# Build list of applications reported by the profiler
	repeat with anItem in o's fullList
		set end of o's reportedApps to first paragraph of anItem
	end repeat
	
	repeat with apath in o's thePaths
		set apath to apath as text
		if apath ends with ".app" then
			if apath is not in o's reportedApps then set end of o's missedApps to apath
		end if
	end repeat
	
	tell application "System Events"
		repeat with i from 1 to count o's missedApps
			set apath to item i of o's missedApps
			set fType to file type of disk item apath
			set item i of o's missedApps to apath & tab & fType
		end repeat
	end tell
	
	set |⌘| to current application
	set anArray to |⌘|'s NSArray's arrayWithArray:(o's missedApps)
	set theNSString to (anArray's componentsJoinedByString:linefeed)
	set theData to (theNSString's dataUsingEncoding:(|⌘|'s NSUTF8StringEncoding))
	-- save data to new file
	set thePath to POSIX path of ((path to desktop as text) & "missedApps.txt")
	set newURL to (|⌘|'s class "NSURL"'s fileURLWithPath:thePath)
	(theData's writeToURL:newURL atomically:true)
	set executeTime to (time of (current date)) - startTime --> 117
end germaine

#=====

on splitString:someText usingString:d1
	set theString to current application's NSString's stringWithString:someText
	set theList to theString's componentsSeparatedByString:d1
	return theList as list
end splitString:usingString:

#=====

What a surprise, numerous apps are reported.

/Applications/Adobe Digital Editions.app
/Applications/Applications perso/Adobe Premiere Elements 11/Adobe Premiere Elements 11.app
/Applications/Applications perso/Adobe Premiere Elements 11/Support Files/Adobe Premiere Elements 11.app
/Applications/Applications perso/Capture NX-D.app
/Applications/Applications perso/darktable.app
/Applications/Applications perso/GIMP-2.10.app
/Applications/Applications perso/HP/HP Utility.app
/Applications/Applications perso/HP Easy Scan.app
/Applications/Applications perso/is 32 bits/Smile/SmileLab droplets/PlotAskColumns.app
/Applications/Applications perso/is 32 bits/Smile/SmileLab droplets/PlotXY.app
/Applications/Applications perso/is 32 bits/Smile/SmileLab droplets/PlotY.app
/Applications/Applications_MAS/Jeux/Garage Inc.app
/Applications/Éditeur AppleScript.app
/Applications/Lexmark/User’s Guide.app
/Applications/Moniteur d’activité.app

Am I doing something wrong or is it really something wrong inn the profiler?

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 3 aout 2019 11:06:57

ADDED : is there a better way to extract the list of strings available in thePaths but not in reportedApps ?

Hi Yvan.

Your script’s not turning up any omissions for me. I don’t know what’s happening on your machine. Do SystemProfiler and FileManagerLib return localised disk item names in the same language?

I don’t know about better, but you may enjoy this:

on germaine()
	# Get array of file paths available in Applications Folder
	set posixPath to POSIX path of (path to applications folder)
	set thePaths to objects of posixPath result type paths list with searching subfolders without include folders and include invisible items
	set thePaths to current application's class "NSArray"'s arrayWithArray:(thePaths)
	
	# Get array of applications reported by the profiler
	set fullReport to do shell script "system_profiler SPApplicationsDataType | sed -En '/^ *Location: (.+)$/ s//\\1/p'"
	set reportedApps to current application's class "NSArray"'s arrayWithArray:(paragraphs of fullReport)
	
	-- Filter 'thePaths' for those with '.app' extensions and which aren't in reportedApps.
	set thePredicate to current application's class "NSPredicate"'s predicateWithFormat:("(self.pathExtension == 'app') AND NOT (self IN %@)") argumentArray:({reportedApps})
	set missedApps to (thePaths's filteredArrayUsingPredicate:(thePredicate)) as list
		
	set p2d to path to desktop as text
	my writeto(p2d & "missedApps.txt", my recolle(missedApps, linefeed), «class utf8», false)
	
	--set my reportedApps to {}
	--set my missedApps to {}
end germaine

Thanks Nigel

I don’t find difference between the way localizable items are treated.
For :

/Applications/Éditeur AppleScript.app
/Applications/Moniteur d’activité.app

I have a track because as you see above, there is an extraneous space which appear after the accented characters when I paste them in this message.

/Applications/Adobe Digital Editions.app
/Applications/Applications perso/HP/HP Utility.app
/Applications/Applications perso/HP Easy Scan.app
are symbolic links too.

More, these two items are in fact soft links which I installed to have the app reachable directly in the Applications folder.

/Applications/Lexmark/User’s Guide.app
/Applications/Applications perso/Adobe Premiere Elements 11/Adobe Premiere Elements 11.app
/Applications/Applications perso/Adobe Premiere Elements 11/Support Files/Adobe Premiere Elements 11.app
are aliases but this time they were not created by me.

/Applications/Applications_MAS/Jeux/Garage Inc.app appears to be a corrupted app whose package contains only its Contents/_MASReceipt folder

/Applications/Applications perso/is 32 bits/Smile/SmileLab droplets/PlotAskColumns.app
/Applications/Applications perso/is 32 bits/Smile/SmileLab droplets/PlotXY.app
/Applications/Applications perso/is 32 bits/Smile/SmileLab droplets/PlotY.app
appear with a ⦰ upon their icons
I will drop the late four items.

So the problem remains only for:
/Applications/Applications perso/darktable.app
/Applications/Applications perso/GIMP-2.10.app

I tried to move them at the first level of the Applications folder but they are ‘missed’ too.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 4 août 2019 10:43:09

I inserted seven instructions in my original script so that it report the file type of every missed item.
You may see the new code in my first message.
It did the job in 22 seconds.

I inserted the seven instructions in the script posted by Nigel. It did the job in 23 seconds.
The difference is meaningless.

As I learnt that Darktable has evolved from version 2.6.0 to 2.6.2, I installed the new version.
It’s reported as missed exactly as the ‘old’ one.

Maybe one of you will be sufficiently curious to download the app from :
https://www.darktable.org/install/#macos
to see if it behaves the same on an other machine.

Here the returned list is :
/Applications/Adobe Digital Editions.app slnk
/Applications/Applications perso/Adobe Premiere Elements 11/Adobe Premiere Elements 11.app fapa
/Applications/Applications perso/Adobe Premiere Elements 11/Support Files/Adobe Premiere Elements 11.app slnk
/Applications/Applications perso/Capture NX-D.app slnk
/Applications/Applications perso/darktable.app APPL
/Applications/Applications perso/GIMP-2.10.app APPL
/Applications/Applications perso/HP/HP Utility.app slnk
/Applications/Applications perso/HP Easy Scan.app slnk
/Applications/Éditeur AppleScript.app slnk
/Applications/Lexmark/User’s Guide.app slnk
/Applications/Moniteur d’activité.app slnk

where
fapa is the file type for standard alias
slnk is the file type for symbolic link
APPL is the file type for application

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 4 août 2019 18:40:12

After rebuilding the indexes of Spotlight both scripts did the job in 5 secons.