title: How to fill the URLs array of the NSOpenPanel with absolute file path?
body: <p>I am trying to create a panel that lets the user choose a path to save a file. When the user selects a directory from the panel that shows relative path (i.e. /folder) the <code>URLs</code> property is contains /folder. When the user selects a directory that shows the full path, <code>URLs</code> property of <code>panel</code> contains the full path (i.e. /User/name/folder). How do I ensure the <code>URLs</code> property will definitely contain the full paths even though the user's panel shows a relative path?</p>
  <pre><code>NSOpenPanel *panel = [NSOpenPanel openPanel];
  [panel setCanChooseFiles:NO];
  [panel setCanChooseDirectories:YES];
  [panel setAllowsMultipleSelection:NO]; // yes if more than one dir is allowed
  
  NSInteger clicked = [panel runModal];
  
  NSArray&lt;NSURL *&gt; *URLs;
  if (clicked == NSFileHandlingPanelOKButton) {
      URLs = [panel URLs];
  }
  else{
      URLs = [NSArray arrayWithObject:[NSURL URLWithString:[NSString stringWithFormat:@&quot;file://%s/&quot;, getenv(&quot;HOME&quot;)]]];
  }
  for (NSURL *url in URLs) { // When user clicks cancel, [panel URLs] is empty
      NSString *selectedDirectoryPath = [url.absoluteString substringFromIndex:6];
  //  NSString *selectedDirectoryPath = [url path];
      NSFileManager *fileManager = [NSFileManager defaultManager];
      NSString *sourceFilePath = [NSString stringWithFormat:@&quot;%@/%@&quot;, NSHomeDirectory(), _fileName];
      NSString *destFilePath = [NSString stringWithFormat:@&quot;%@%@&quot;, selectedDirectoryPath, _fileName];
  }
  </code></pre>
  <p>I thought I could use the path instance property on url, but the array is filled once the user clicks OK to a file path with NSFileHandlingPanelOKButton.</p>
  <p>Edit: I found a response that suggests to use <code>beginSheetModalForWindow</code> in <a href="https://stackoverflow.com/questions/7867076/nsopenpanel-url-to-string">NSOpenPanel URL to string</a> , but how do you use this function?</p>