[foo modified] is returning YES for unmodified docs... (objc-appscript framwork)

Discussion in 'Mac Programming' started by Warhaven, Mar 4, 2010.

  1. Warhaven macrumors newbie

    Mar 3, 2010
    So I have something very simple (using objc-appscript framework):

    if ([pagesApp isRunning]) {
    	PGReference *realRef = [pagesApp documents];
    	if( [realRef modified] ) {
    		NSLog(@"Doc modified... saving.");
    		[[realRef save] send];
    And even when the documents were recently saved and nothing's been done to them, [realRef modified] is still returning YES...

    Any thoughts? Not quite sure what I'm doing wrong here...
  2. hhas macrumors regular

    Oct 15, 2007
    1. Appscript doesn't do 'implicit gets' as AppleScript does. You need to send a 'get' event to Pages to get the value of the 'modified' property. Longhand would be:

    [[[realRef modified] get] send]
    but this can be shortened to:

    [[realRef modified] getItem]
    2. Appscript uses its own ASBoolean class to represent Boolean values, so remember to call -boolValue on an ASBoolean instance to get a BOOL.

    As your code is asking for the modified values of all documents, you're going to get an NSArray of ASBoolean instances, so you'll have to go through and check each one in turn.

    Also remember that ObjC exceptions are reserved for serious (i.e. programmer) errors only. Normal application errors are indicated by nil results and/or NSError** args, so check those as needed.

    BTW, you might run into problems with your 'save' command if any of the documents are newly created and haven't previously been saved to disk. (I think Cocoa apps tend to throw up Save dialogs in this situation, which isn't very clever.) But that's a general application scripting issue, not an appscript-specific one.
  3. Warhaven thread starter macrumors newbie

    Mar 3, 2010
    Thank you for the reply. I've been working on it some more, and I've solved both problems. I don't really need to check if the document has been modified or not in order to the send the save command, so I've simply done away with that.

    The saving issue I resolved by doing the following:

    PGReference *realRef = [pagesApp documents];
    NSArray *pathArray = [NSArray arrayWithArray: [[realRef path] getItem]];
    for (int i = 0; i < [pathArray count]; i++) {
    	// [PGConstant missingValue] == New Document
    	if([[pathArray objectAtIndex:i] isNotEqualTo:[PGConstant missingValue]]) {
    		// Do something
    I just grab all the paths to the open documents. If it returns a missing value, then I know it's a fresh document.


    Oh, i see what you mean by the save dialog causing a problem. It stalls the thread until the user has finished dealing with it. I think what I'll do is sort the array and save everything that has a path right away, and then deal with the items that don't have one last or start a thread pool and assign a thread to each document attempting to save so as not to hold up everything.

    Now I just need to learn how to do thread pools. :) Unless you have a better suggestion for handling it...

Share This Page