use framework "Foundation"
on readFile:thePath
set anNSURL to current application's NSURL's fileURLWithPath:thePath
set theScript to current application's NSAppleScript's alloc()'s initWithContentsOfURL:anNSURL |error|:(missing value)
set theSource to theScript's richTextSource()
set pb to current application's NSPasteboard's generalPasteboard()
pb's clearContents()
pb's writeObjects:{theSource}
end readFile:
When you run it, it will put the styled contents of the script at thePath on your clipboard -- no need to go near the settings.
I don’t think that Xcode is necessarily doing anything with the formatting preferences since it doesn’t use them, but something is getting confused when using it with the AppleScript Editor - I’ve never had a problem just using the AppleScript Editor by itself.
You could always try another editor for a few days, and see if it still happens. But if it's something else, which I suspect, it won't prove a lot.
I’m not manipulating the preferences file while the applications are running, but before Mavericks, just quitting the applications and restoring the file was enough. Now when it gets lost, it takes a restart to clean things up or to get it to read the file again (or at least pay attention to it).
AppleScript Editor doesn't read (or write) the file. And I doubt it even uses defaults. There are special APIs for the syntax styles (ASCopySourceAttributes() and
ASSetSourceAttributes()), which tell an AppleScript instance to fetch or modify them, presumably using the defaults mechanism, which in turn writes the file when it feels like it (not often in Mavericks). My guess would be that corruption occurs when an attempt is made to make access them on separate instances at the same time. But that brings us back to the question of what is doing it, and I don't think Xcode is involved directly (but I suppose it could be be triggering a QuickLook plug-in).