0

I'm having some trouble getting this NSTask to launch from an NSPopover view. The popover I created has several things in it. First the user selects a path using NSOpenPanel, then the user enters a username so that I can construct a path to transfer data to. Finally, there's a button that is supposed to launch the NSTask that initiates the data transfer. I had to add some extra code to make the text field work for user input. See the following link for what I followed to get the text field to work: NSStatusItem with NSPopover and NSTextField

Any reason why this wouldn't work? This code had been working when it was contained in a NSWindow.

- (IBAction)beginTransfer:(id)sender {

//Construct a string of the user selected source path.
NSString *userAccountPath = [_sourcePathTextField stringValue];

//Check that I got the expected result
NSLog (@"%@", userAccountPath);

//Create an array with the pieces I need to construct a destination account path
NSArray *strings = [NSArray arrayWithObjects:@"/Users/", [userAccountTextField stringValue], nil];

//Construct a string destination account location from the pieces
NSString *userAccountDestinationPath = [strings componentsJoinedByString:@""];

//Make sure the construction is correct
NSLog (@"%@", userAccountDestinationPath);

//Setup NSTask
NSTask *transferFiles;
transferFiles = [[NSTask alloc] init];

//Arguements for rsync
NSArray *arguements;
arguements = [NSArray arrayWithObjects:@"--paH", @"--info=progress2", @"--human-readable", @"--exclude", @"/Library/Keychains", userAccountPath, userAccountDestinationPath, nil];

//Setup output pipe
NSPipe *transferOutput = [NSPipe pipe];
[transferFiles setStandardOutput:transferOutput];

//Launch rsync with arguements from above
[transferFiles setArguments:arguements];

[transferFiles setLaunchPath:@"/usr/local/bin/rsync"];
[transferFiles launch];

NSFileHandle *fh = [transferOutput fileHandleForReading];
[fh waitForDataInBackgroundAndNotify];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedData:) name:@"NSFileHandleDataAvailableNotification" object:nil];

[transferFiles waitUntilExit];
[transferFiles release];
[fh release];

}

Community
  • 1
  • 1
dzimmerl
  • 35
  • 1
  • 5

0 Answers0