AppleScripting "Save As" in a CoreData application

  • [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.


    Doug Knowles
previous month october 2007 next month
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today