title: Default Save location of document in Cocoa document based application
body: <p>I have created a Cocoa document based picture drawing application. I want that the default location of a new document created using my app in Save/Save As dialog should be in ~/Pictures/MyAppName/ directory.</p>
  
  <p>How can I achieve this?</p>
  
  <p>I tried more or less what Ole suggested below, but it doesn't work. Here is my implementation of prepareSavePanel. What am I doing wrong?</p>
  
  <pre><code>- (BOOL)prepareSavePanel:(NSSavePanel *)savePanel
  {
      if ([self fileURL] == nil) {
          //new, not saved yet
          [savePanel setExtensionHidden:NO];
  
          //set default save location        
          NSArray *paths = NSSearchPathForDirectoriesInDomains(NSPicturesDirectory, NSUserDomainMask, YES);
  
          if ([paths count] &gt; 0) {
              NSString *userPicturesPath = [paths objectAtIndex:0];
              NSString *myDirPath = [userPicturesPath stringByAppendingPathComponent:@"MyAppName"];
  
  
              //create directory is it doesn't already exist
              NSFileManager *fileManager = [NSFileManager defaultManager];
              BOOL isDir;
              BOOL useMyAppDir = NO;
              if([fileManager fileExistsAtPath:myDirPath isDirectory:&amp;isDir]){
                  if (isDir) {
                      useMyAppDir = YES;
                  }
              } else {
                  //create the directory
                  if([fileManager createDirectoryAtPath:myDirPath withIntermediateDirectories:YES attributes:nil error:nil]){
                      useMyAppDir = YES;
                  }
              }
  
              if (useMyAppDir) {
                  NSURL * myAppDirectoryURL = [NSURL URLWithString:myDirPath];
                  [savePanel setDirectoryURL:myAppDirectoryURL];
              }
          }
      } else {
          [savePanel setExtensionHidden:[self fileNameExtensionWasHiddenInLastRunSavePanel]];
      }
  
      return YES;
  }
  </code></pre>