remove plist

Hey all.


I have a question about removing .plist files.


I am using a command to find and log the files but would like to be able to move those files to the trash.


For the life of me I cant figure out how to get the output to move these files to the trash.


do shell script "plutil -s ~/Library/Preferences/*.plist > ~/Desktop/badplistfiles.txt" with administrator privileges

Posted on Jun 9, 2014 7:43 AM

Reply
5 replies

Jun 9, 2014 9:07 AM in response to John Antolino

Try using:


set the_plists to (do shell script "plutil -s ~/Library/Preferences/*.plist")

repeat with this_path in paragraphs of the_plists

set this_path to items 1 thru ((offset of ":" in this_path) - 1) of this_path as string

set the_name to POSIX file this_path

tell application "Finder"

set the_name to name of (the_name as alias)

end tell

do shell script "mv '" & this_path & "' ~/.Trash/'" & the_name & "'"

end repeat


(108032)

Jun 9, 2014 9:24 AM in response to John Antolino

I'm not sure why you are running this with administrator privileges. You shouldn't have to. Parsing the output file for pathnames is more work than it is worth. plutil runs fairly quickly. So, I'll suggust that you run your command to produce the badplistfiles.txt. plutil exits with a non zero exit code if it finds a corrupt plist file. You could send standard out and standard error to the bit bucket then use "||"- "logical or" to move the corrupt plist file(s).


for i in ~/Library/Preferences/*.plist; do
plutil "${i}"  > /dev/null 2>&1 || mv "${i}" ~/.Trash
done

You could write it in a single line like this


for i in ~/Library/Preferences/*.plist; do plutil "${i}"  > /dev/null 2>&1 || mv "${i}" ~/.Trash; done

You'll have to figure out how to escape the quotes in a do shell script statement. I'm not an AppleScripter.

Jun 9, 2014 1:08 PM in response to John Antolino

Hello


You may also try something like this in shell:


plutil -s ~/Library/Preferences/*.plist |   # validate plists and only write bad list
tee ~/Desktop/badplistfiles.txt |           # write bad list to a log file
perl -l0pe 's/:.*$//og' |                   # extract plist paths from bad list (string before :, null-terminated)
xargs -0 -J% mv % ~/.Trash                  # move bad plists to Trash



From AppleScript:


do shell script "
plutil -s ~/Library/Preferences/*.plist |   # validate plists and only write bad list
tee ~/Desktop/badplistfiles.txt |           # write bad list to a log file
perl -l0pe 's/:.*$//og' |                   # extract plist paths from bad list (string before :, null-terminated)
xargs -0 -J% mv % ~/.Trash                  # move bad plists to Trash
"


Regards,

H

Jun 9, 2014 2:11 PM in response to Mark Jalbert

Had to write it like this but it worked

For some reason do shell script did not work for me because of token issues. But typing it into terminal using System Events did the trick

Thanks again.


tell application "Terminal"

activate

tell application "System Events" to keystroke "for i in ~/Library/Preferences/*.plist; do plutil \"${i}\" > /dev/null 2>&1 || mv \"${i}\" ~/.Trash/PinWheel\\ Garbage\\ Files/SystemCaches; done"

delay 2

tell application "System Events" to keystroke return

end tell

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

remove plist

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.