repeat with aFile in filesToDeleteLA
try
do shell script “/bin/rm /Applications/Library/LaunchAgents/” & aFile with administrator privileges
end try
end repeat
As I said 3 other of routine work that look like this but this does not delete my test files.
BigJack helps you in advance and I’m not really that big! OS X 10.9.5
second of all, the LaunchAgents folder is in /Library, not in /Applications
third of all, for developing scripts remove any try blocks to get at least error messages
property filesToDeleteLA : {"com.vsearch.agent.plist", "com.conduit.loader.agent.plist", "com.genieoinnovation.macextension.plist", "com.genieoinnovation.macextension.client.plist", "com.genieo.engine.plist", "com.genieo.completer.update.plist"}
repeat with aFile in filesToDeleteLA
-- try
do shell script "/bin/rm /Library/LaunchAgents/" & aFile with administrator privileges
-- end try
end repeat
For the record: Stefan’s answer is correct, this is just another more efficient approach.
rm takes multiple file path arguments, the code below have much more lines but is still more efficient. That is because invoking a shell does cost time. If that list is every going to be variable, then you should definitely use quoted form of too when using paths in do shell scripts.
set filesToDeleteLA to {"com.vsearch.agent.plist", "com.conduit.loader.agent.plist", "com.genieoinnovation.macextension.plist", "com.genieoinnovation.macextension.client.plist", "com.genieo.engine.plist", "com.genieo.completer.update.plist"}
-- set every item in the list to a full quoted file path
repeat with i from 1 to count filesToDeleteLA
set item i of filesToDeleteLA to quoted form of ("/Library/LaunchAgents/" & item i of filesToDeleteLA)
end repeat
-- create a bash lists from AppleScript list
set oldTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to space
set theFiles to filesToDeleteLA as string
set AppleScript's text item delimiters to oldTIDs
--remove the items in one single command
do shell script "rm " & theFiles