문제

I'm attempting to modify a Quicksilver plugin (screen capture) in Xcode, in order to allow the screencapture destination path to be set to the defaults com.apple.screencapture path value. The plugin currently has the path hardcoded for some reason, so even when you've changed the OSX default path for screen captures, the plugin still sends them to the OSX default, which is the desktop.

I'm a literal noob with Xcode/Objective C, so any info/examples or point in the right direction would be much appreciated.

The screencapture plugin file which needs to be tweaked is the "QSScreenCapturePlugIn.m" file - here's a snippet:

(QSObject *)captureRegion:(QSObject *)dObject{

   NSString *destinationPath=[@"~/Desktop/Picture.png" stringByStandardizingPath];

   destinationPath=[destinationPath firstUnusedFilePath];

   NSTask *task=[NSTask launchedTaskWithLaunchPath:SCTOOL arguments:[NSArray arrayWithObjects:@"-is",destinationPath,nil]];

   [task waitUntilExit];

   [[QSReg preferredCommandInterface] selectObject:[QSObject fileObjectWithPath:destinationPath]];

   [[QSReg preferredCommandInterface] actionActivate:nil];
   return nil;
}

I've searched high and low for examples demonstrating how to read from the defaults database, but it seems information is sparse.

Thanks!

도움이 되었습니까?

해결책

I can't believe no one was able to help out with an answer or pointer on this one (or maybe I'm just not patient enough), but thankfully I was able to find the answer while reading through some other answers here on SO - unfortunately I can't reference the Question here, since I lost the page.

Anyway, this will do it:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

NSString *screenCaptureLocationString = [[defaults persistentDomainForName:@"com.apple.screencapture"] valueForKey:@"location"];

Amazingly hard to find this info for some reason, but hopefully posting it here will help someone else.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top