On Nov 27, 2013, at 2:18 PM, David Duncan <david.dun...@apple.com> wrote:

> The preferences file has always been considered an implementation detail. I'm 
> not up on all the reasons for the change, but you should be able to use the 
> 'defaults' command line tool to do the same thing that trashing prefs used to 
> do. Something like 'defaults delete com.yourcompany.yourapp' should do the 
> trick.
> 
>> On Nov 27, 2013, at 2:02 PM, Graham Cox <graham....@bigpond.com> wrote:
>> 
>> Apparently, OS X 10.9 caches preference files. This is the first I’ve heard 
>> about it (on a discussion on Ars Technica of all places). Is there any 
>> documentation about this, like an explanation as to what purpose this has?
>> 
>> ....
>> 
>> Please someone tell me there’s a way to opt out of this travesty? At this 
>> rate I’ll be writing a full-on replacement for NSUserDefaults just to get 
>> back the behaviour it’s always had in the past. What good is this change 
>> anyway?


On one of the forums or mailing lists a little while ago, an apparently 
knowledgeable Apple engineer reported that it has NEVER been proper to manually 
delete preferences files but that it did happen to work most of the time before 
Mavericks. Now in Mavericks it doesn't work, as you've discovered. Here is an 
AppleScript (written using new Mavericks techniques, so don't run it on older 
systems) that I wrote to do it right using the defaults tool. I put this script 
in my Script Menu and it is now even easier than before to delete preferences 
files. (But note the caution at the end about Sandboxed applications, for which 
I don't have an answer.)

(*
This script removes the preferences cache and file for non-sandboxed 
applications.
Starting with Mavericks, application preferences may be cached in such a way 
that deleting a preferences file is not immediately effective. This script for 
OS X 10.9 Mavericks immediately removes any cached preferences for the chosen 
application and then deletes the preferences file or files. The script reports 
whether cached preferences were found and deleted before giving you the option 
to delete the preferences file or files. The application must not be running. 
Authentication with an administrator password is required.
*)

use scripting additions

choose application with title "Delete Preferences for Application" with prompt 
"Choose an application:" as alias
set info to (info for result)
set displayName to displayed name of info
if application displayName is running then
        display alert "\"" & displayName & "\" is running." message 
"Preferences should not be deleted while the application is running. Quit 
application \"" & displayName & "\" and run this script again." buttons {"OK"} 
default button "OK"
else
        set bundleID to bundle identifier of info
        try
                do shell script "defaults delete -app " & quoted form of 
displayName with administrator privileges
                display alert "Cached preferences of \"" & displayName & "\" 
were deleted." message "You can now delete the preferences file." buttons 
{"Cancel", "Delete"} default button "Delete" cancel button "Cancel"
        on error errMsg number errNum
                if errNum is 1 then
                        display alert "\"" & displayName & "\" has no cached 
preferences." message "You can delete the preferences file." buttons {"Cancel", 
"Delete"} default button "Delete" cancel button "Cancel"
                end if
        end try
        do shell script "rm -rf ~/Library/Preferences/" & bundleID & "*" -- for 
non-sandboxed apps
        
        -- The following statement removes the preferences file from a 
sandboxed application's container, but then the application's preferences 
system gets confused and the application will not create a new preferences 
file. Therefore, don't do it.
        --do shell script "rm -rf ~/Library/Containers/" & bundleID & 
"*/Data/Library/Preferences/" & bundleID & "*" -- for sandboxed apps
end if

-- 

Bill Cheeseman - b...@cheeseman.name

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to