All startup locations?

I try to find all places where software/code is run (on boot).

-StartupItems
-Preference Panes
-Services
-System-Library-Extensions
-Contextual Menu Items
-Launch Agents
-Launch Daemons
-LoginPlugins
-loginwindow.plist
-Menu Extras
-QuickLook plugins
-Spotlight plugins
-QuickTime plugins
-Widgets
???

This gives the full list of startup items on computer:


set allStartupItemslist to paragraphs of (do shell script "launchctl list" with administrator privileges)
set filteredNamesList to {}

repeat with i from 1 to (count of allStartupItemslist)
	set theText to item i of allStartupItemslist
	repeat with j from (count of theText) to 1 by -1
		if character j of theText = "	" then exit repeat
	end repeat
	set theText to text (j + 1) thru -1 of theText
	if theText contains "." then set end of filteredNamesList to theText
end repeat
filteredNamesList

I will search, but maybe someone knows already how I can convert this list of startup items to the list of its locations?

@KniazidisR

Here is a quick and dirty attempt to fit your needs but I’m not sure that it’s what cirno asked for.

script o
	property allStartupItemslist : {}
	property startupItems : {}
	property launchItems : {}
	property thePaths : {}
	property missing : {}
end script

set o's allStartupItemslist to rest of paragraphs of (do shell script "launchctl list" with administrator privileges)

repeat with anitem in o's allStartupItemslist
	set end of o's startupItems to item -1 of my decoupe(anitem, tab)
end repeat


set aPath to (path to library folder) as text
tell application "System Events"
	set partialList to path of files of folder (aPath & "LaunchAgents")
	set o's launchItems to o's launchItems & result
	set partialList to path of files of folder (aPath & "LaunchDaemons")
	set o's launchItems to o's launchItems & result
end tell
set aPath to (path to library folder from system domain) as text
tell application "System Events"
	set partialList to path of files of folder (aPath & "LaunchAgents")
	set o's launchItems to o's launchItems & result
	set partialList to path of files of folder (aPath & "LaunchDaemons")
	set o's launchItems to o's launchItems & result
end tell
set aPath to (path to library folder from user domain) as text
tell application "System Events"
	set partialList to path of files of folder (aPath & "LaunchAgents")
	set o's launchItems to o's launchItems & result
end tell
repeat with anitem in o's startupItems
	set anitem to anitem as text
	set found to false
	repeat with aPath in o's launchItems
		
		if (aPath as text) contains anitem then
			set found to true
			set end of o's thePaths to aPath as text
			exit repeat
		end if
	end repeat
	if not found then set end of o's missing to anitem
end repeat
{o's thePaths, linefeed & linefeed & linefeed, o's missing}


#=====

on decoupe(t, d)
	local oTIDs, l
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set l to text items of t
	set AppleScript's text item delimiters to oTIDs
	return l
end decoupe

#=====

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 7 aout 2019 19:02:06

It would be interesting to compare the results of your script with the results of my script:


use AppleScript version "2.5" -- macOS 10.11 or later
use scripting additions
use script "Metadata Lib" version "2.0.1"

set theFolder to POSIX path of (path to startup disk)

set allStartupItemslist to paragraphs of (do shell script "launchctl list" with administrator privileges)
set filteredNamesList to my FilterTheList(allStartupItemslist)

set theLocationsList to {}
repeat with i from 1 to (count of filteredNamesList)
	set theName to quoted form of (item i of filteredNamesList)
	set theFile to (perform search in folders {theFolder} predicate string "kMDItemFSName CONTAINS[c] " & theName)
	if theFile ≠ {} then
		set theFile to ((item 1 of theFile) as POSIX file) as alias
		tell application "System Events" to set theLocation to POSIX path of (container of theFile)
		if not (theLocationsList contains theLocation) then set theLocationsList to theLocationsList & theLocation
	end if
end repeat

on FilterTheList(allStartupItemslist)
	set filteredNamesList to {}
	repeat with i from 1 to (count of allStartupItemslist)
		set theText to item i of allStartupItemslist
		repeat with j from (count of theText) to 1 by -1
			if character j of theText = "	" then exit repeat
		end repeat
		set theText to text (j + 1) thru -1 of theText
		if theText contains "." then set end of filteredNamesList to theText
	end repeat
	return filteredNamesList
end FilterTheList

theLocationsList

I will test when you will have corrected your code.

At this time it issue the error:
error “Impossible de convertir "" en type POSIX file.” number -1700 from “” to POSIX file
generated by the instruction
set theFile to (theFile as POSIX file) as alias

First thing to do is to edit the first instruction as:

set allStartupItemslist to rest of paragraphs of (do shell script “launchctl list” with administrator privileges)
so it will drop the list of headers : “PID Status Label”

If I understand well, theFile is supposed to be a POSIX path .
If I am right, it would be better to replace
set theFile to (theFile as POSIX file) as alias
by
set theFile to (POSIX file theFile) as alias

There is also something wrong in your handler which return a lis of items resembling to
“61 0 com.malwarebytes.mbam.rtprotection.daemon”
when they are supposed to resemble to
“com.malwarebytes.mbam.rtprotection.daemon”,

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 7 aout 2019 19:39:39

Three missing items:
“com.apple.DesktopServicesHelper.CFD56B10-F22D-4416-A146-ADD99E2D98BB”
“com.apple.DesktopServicesHelper.6395B212-8872-4C53-9513-A5954FD036C1”
“com.apple.DesktopServicesHelper.BCE77C3A-413F-4172-AAD3-E251C30BBA93”
“belong” to
“SSD 500:System:Library:LaunchDaemons:com.apple.DesktopServicesHelper.plist”

“com.apple.security.authhost.00000000-0000-0000-0000-0000000186A7”
“belongs” to “SSD 500:System:Library:LaunchDaemons:com.apple.security.authhost.plist”

“com.apple.security.agent.login.00000000-0000-0000-0000-0000000186A7”
“belongs” to “SSD 500:System:Library:LaunchDaemons:com.apple.security.agent.login.plist”

Other missing items have no matching plist.
{“com.apple.EmbeddedOSInstallService”, “com.apple.iBooksX-SecureUserDefaults”, “com.apple.nsurlsessiond_privileged”, “com.apple.mDNSResponderHelper.reloaded”, “com.apple.cmio.registerassistantservice”, “com.apple.signpost.signpost-notificationd”, “com.apple.authd”, “com.apple.nlcd”, “com.apple.AccountPolicyHelper”, “com.apple.nfrestore_service”, “com.apple.siri.acousticsignature”, “com.apple.systempreferences.cacheAssistant”, “com.apple.systemadministration.writeconfig”, “com.apple.mDNSResponder.reloaded”, “com.apple.findmymacd”, “com.apple.Localization.SetDefaultsService”, “com.apple.iokit.ioserviceauthorized”, “com.apple.AmbientDisplayAgent”, “com.apple.internal.aupbregistrarservice”, “com.apple.CodeSigningHelper”}

If I run a code similar to yours:

set theMissings to {"com.apple.EmbeddedOSInstallService", "com.apple.iBooksX-SecureUserDefaults", "com.apple.nsurlsessiond_privileged", "com.apple.mDNSResponderHelper.reloaded", "com.apple.cmio.registerassistantservice", "com.apple.signpost.signpost-notificationd", "com.apple.authd", "com.apple.nlcd", "com.apple.AccountPolicyHelper", "com.apple.nfrestore_service", "com.apple.siri.acousticsignature", "com.apple.systempreferences.cacheAssistant", "com.apple.systemadministration.writeconfig", "com.apple.mDNSResponder.reloaded", "com.apple.findmymacd", "com.apple.Localization.SetDefaultsService", "com.apple.iokit.ioserviceauthorized", "com.apple.AmbientDisplayAgent", "com.apple.internal.aupbregistrarservice", "com.apple.CodeSigningHelper"}
set theFiles to {}
repeat with aMissing in theMissings
	set theName to quoted form of aMissing
	
	set theFile to (do shell script "mdfind 'kMDItemFSName' contains theName")
	set end of theFiles to theFile
end repeat
theFiles

it return:

{“/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt", "/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt”, “/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt", "/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt”, “/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt", "/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt”, “/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt", "/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt”, “/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt", "/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt”, “/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt", "/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt”, “/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt", "/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt”, “/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt", "/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt”, “/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt", "/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt”, “/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt", "/Users//Library/Autosave Information/Document Éditeur de script 5 non enregistré.scpt”}

which is not what you hoped to get.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 7 aout 2019 19:53:08

Now I updated my code. It gives me 17 locations on my computer. The interesting: some daemons have not kMDItemFSName.

THE RESULT:

{“/System/Library/LaunchDaemons”, “/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Resources”, “/System/Library/LaunchAgents”, “/System/Library/Sandbox/Profiles”, “/System/Library/CacheDelete”, “/System/Library/PrivateFrameworks/BookKit.framework/Versions/A/XPCServices”, “/Library/LaunchDaemons”, “/System/Library/Frameworks/CoreMediaIO.framework/Versions/A/XPCServices”, “/System/Library/PrivateFrameworks/AccountPolicy.framework/XPCServices”, “/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/share/man/man8”, “/System/Library/PrivateFrameworks/AssistantServices.framework/Versions/A/XPCServices”, “/Users/123/Library/Containers”, “/System/Library/Frameworks/PreferencePanes.framework/Versions/A/XPCServices”, “/System/Library/PrivateFrameworks/PerformanceAnalysis.framework/Versions/A/XPCServices”, “/System/Library/PrivateFrameworks/AmbientDisplay.framework/Versions/A/XPCServices”, “/System/Library/DifferentialPrivacy/Configuration”, “/System/Library/Frameworks/Security.framework/Versions/A/XPCServices”}

OK. THE RESULT IS SAME.

30 daemons are embedded in System and have not the paths

A quick look teach that :
“/System/Library/LaunchDaemons” is a folder
“/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Resources” is a folder
“/System/Library/LaunchAgents” is a folder
“/System/Library/Sandbox/Profiles” is a folder
“/System/Library/CacheDelete” is a folder
“/System/Library/PrivateFrameworks/BookKit.framework/Versions/A/XPCServices” is a folder
“/Library/LaunchDaemons” is a folder
“/System/Library/Frameworks/CoreMediaIO.framework/Versions/A/XPCServices” is a folder
“/System/Library/PrivateFrameworks/AccountPolicy.framework/XPCServices” is a folder
“/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/share/man/man8” is a folder
“/System/Library/PrivateFrameworks/AssistantServices.framework/Versions/A/XPCServices” is a folder
“/Users/123/Library/Containers” is a folder
“/System/Library/Frameworks/PreferencePanes.framework/Versions/A/XPCServices” is a folder
“/System/Library/PrivateFrameworks/PerformanceAnalysis.framework/Versions/A/XPCServices” is a folder
“/System/Library/PrivateFrameworks/AmbientDisplay.framework/Versions/A/XPCServices” is a folder
“/System/Library/DifferentialPrivacy/Configuration” is a folder
“/System/Library/Frameworks/Security.framework/Versions/A/XPCServices” is a folder

Among the missings returned by my script,

com.apple.iBooksX-SecureUserDefaults is related to the package “SSD 500:System:Library:PrivateFrameworks:BookKit.framework:Versions:A:XPCServices:com.apple.iBooksX-SecureUserDefaults.xpc:” or to the folder “SSD 500:Users:yvankoenig:Library:Containers:com.apple.iBooksX-SecureUserDefaults:”

com.apple.cmio.registerassistantservice is related to the package “SSD 500:System:Library:Frameworks:CoreMediaIO.framework:Versions:A:XPCServices:com.apple.cmio.registerassistantservice.xpc:”

com.apple.signpost.signpost-notificationd is related to the folder “SSD 500:Users:yvankoenig:Library:Containers:com.apple.signpost.signpost-notificationd:”

com.apple.authd is related to the file “SSD 500:private:etc:asl:com.apple.authd” or to the file “SSD 500:System:Library:Sandbox:Profiles:com.apple.authd.sb”

com.apple.nlcd is related to the file “SSD 500:System:Library:Sandbox:Profiles:com.apple.nlcd.sb”

com.apple.AccountPolicyHelper is related to the package “SSD 500:System:Library:PrivateFrameworks:AccountPolicy.framework:XPCServices:com.apple.AccountPolicyHelper.xpc:” or to the file “Macintosh HD:private:etc:asl:com.apple.AccountPolicyHelper”

com.apple.siri.acousticsignature is attached to the package “SSD 500:System:Library:PrivateFrameworks:AssistantServices.framework:Versions:A:XPCServices:com.apple.siri.acousticsignature.xpc:”

com.apple.systempreferences.cacheAssistant is related to the folder “SSD 500:Users:yvankoenig:Library:Containers:com.apple.systempreferences.cacheAssistant:”

com.apple.Localization.SetDefaultsService is related to the package “SSD 500:System:Library:Frameworks:PreferencePanes.framework:Versions:A:XPCServices:com.apple.Localization.SetDefaultsService.xpc:”
or to the folder “SSD 500:Users:yvankoenig:Library:Containers:com.apple.Localization.SetDefaultsService:”

com.apple.AmbientDisplayAgent is related to the package “SSD 500:System:Library:PrivateFrameworks:AmbientDisplay.framework:Versions:A:XPCServices:com.apple.AmbientDisplayAgent.xpc:”
or to the folder “SSD 500:Users:yvankoenig:Library:Containers:com.apple.AmbientDisplayAgent:”

com.apple.CodeSigningHelper is related to the package “SSD 500:System:Library:Frameworks:Security.framework:Versions:A:XPCServices:com.apple.CodeSigningHelper.xpc:”
or to the file “SSD 500:System:Library:Sandbox:Profiles:com.apple.CodeSigningHelper.sb”

I really don’t see how you may write about the results of our scripts : “they are the same”

It would be a good idea to update your copy of “Metada Lib” to version 2.0.2 which brought some corrections.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 7 aout 2019 21:38:30

Yvan,

I wanted the result of the locations as folders, so it is what I wanted for me. I wanted as the OP, all places.

Then I inserted the return filteredNamesList and this list has as result 327 daemons as with your script too.