Deleting plist files

Hello! First post here.

I need to have a script that would delete a bunch of app’s plist files. However, one of them (version 12) has a slightly different domain name due to the old company name. And if iterate over it with the repeat command, it wouldn’t skip over “12” and still use this value to look for and delete a newcompanyname plist. How do I exclude it from iterating it in the list of app versions?


on run
	
	set appVersionList to {"12", "13", "14", "15", "16"}
	
	--choice: reset preferences
	set resetChoice to (display dialog "Reset application preferences?" buttons {"Reset", "Cancel"} default button "Reset")
	
	if button returned of resetChoice is "Reset" then
		tell application ("App Name ")
			quit
		end tell
		delay 3
		repeat with appVersion in appVersionList
			if appVersion is equal to "12" then
				do shell script "defaults delete com.oldcompanyname.appname" & appVersion & ""
			else
				set appVersionList to {"13", "14", "15", "16"}
				do shell script "defaults delete com.newcompanyname.appname" & appVersion & ""
			end if
		end repeat
	end if
end run

I don’t really understand your logic here as it seems like you are trying to change appVersionList mid-loop.

That aside, the reason your script is not honouring the first ‘if’ is because the comparison isn’t what you think it is. As a consequence, the ‘12’ comparison ends up being handled under ‘else’, along with the rest of the numbers.

Try inserting contents of into the line, like so:

if contents of appVersion is "12" then

Right now, the comparison —if broken down— would be something like this:

if item appVersion of appVersionList is equal to "12" then

Putting ‘contents of’ will dereference appVersion and let the proper comparison take place.

1 Like

Thanks! It seems like I’ve pasted the earlier iteration of this script where I tried to change the list and see if that would work. I’m a bit more versed in Python, so I though changing the list would work.

Unfortunately, that doesn’t work as it might.

You can change the value of the loop variable inside the loop body but it will get reset to the next loop value the next time through the loop.

1 Like