Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top