AppleScripting "Save As" in a CoreData application
AppleScripting "Save As" in a CoreData application
- Subject: AppleScripting "Save As" in a CoreData application
- From: "Doug Knowles" <email@hidden>
- Date: Sat, 20 Oct 2007 15:40:56 -0400
[Cross-posting to cocoa-dev & applescript-implementors because both seem
equally relevant; I hope this is OK...]
I think this should be easier than I'm making it, but I've been stumped by
this for a few days (part-time):
I'm working on the scriptability of my application and writing "smoke test"
scripts in parallel, and one of the first things I want to do is the
equivalent of the standard "Save As..."; save an existing document to a new
file and associate the open document with the new file.
If I try "save theDocument in file foo", NSPersistentDocument throws an
exception that it doesn't support "save to" operations (which, I assume,
saves the contents to a different file but keeps the original associated
with the open document). If AppleScript "save in file" equates to
"save-to", I can't see how to express "save-as" in AppleScript in the
standard suite.
Since I can't have and don't need "save-to", I've tried tricking
NSPersistentDocument into doing what I want by:
- changing the writeToUrl:ofType:forSaveOperation:... methods
NSSaveOperation value from NSSaveToOperation to NSSaveAsOperation in by
sub-class method before passing it up to the superclass;
- overriding handleSaveScriptOperation: to call setFileURL: after its normal
processing (including the call to my modified writeToUrl:...) is done.
This doesn't work (the open document loses complete track of what it's file
is supposed to be), and I've stopped exploring this option before I pegged
the kludge meter.
Is there a simpler way to approach this?
If all else fails, I'll revert to closing the document, copying it with the
Finder, and re-opening, but this involves overhead and side-effects I'd
rather not incur.
TIA,
Doug Knowles
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden