diff options
| author | Teddy Wing | 2012-07-21 02:14:35 -0400 | 
|---|---|---|
| committer | Teddy Wing | 2012-07-21 02:14:35 -0400 | 
| commit | 0a46e02d9fc2d5671b5454d9c9fe991158c8e304 (patch) | |
| tree | d67771d6474be5179173835fbbd4ef5b7c064b26 | |
| parent | f4c76d74ecb66bad371fbf0337c6dbfbe3c8188a (diff) | |
| download | On-Task-0a46e02d9fc2d5671b5454d9c9fe991158c8e304.tar.bz2 | |
Changed 'supportPath' variable name to 'applicationSupportPath'. Longer but more descriptive.
Screenshots now get saved into a "Screenshots" directory inside the Application Support directory. We have to check to see if it's there and create it if not.
| -rw-r--r-- | On Task.m | 12 | 
1 files changed, 10 insertions, 2 deletions
| @@ -6,7 +6,7 @@ int main (int argc, const char * argv[]) {      NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];  	// Get Application Support dir path -	NSString *supportPath = [[NSFileManager defaultManager] applicationSupportDirectory]; +	NSString *applicationSupportPath = [[NSFileManager defaultManager] applicationSupportDirectory];  	// Get a date string  	[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4]; @@ -15,9 +15,17 @@ int main (int argc, const char * argv[]) {  	NSString *date = [df stringFromDate:[NSDate date]];      // # Take screenshot +	// Make screenshots directory if needed +	NSString *screenshotsPath = [applicationSupportPath stringByAppendingString:@"/Screenshots"]; +	if (![[NSFileManager defaultManager] fileExistsAtPath:screenshotsPath]) { +		if (![[NSFileManager defaultManager] createDirectoryAtPath:screenshotsPath attributes:nil]) { +			NSLog(@"Error: Could not create folder %@", screenshotsPath); +		} +	} +	  	NSTask *takeScreenshot = [[NSTask alloc] init];  	[takeScreenshot setLaunchPath:@"/usr/sbin/screencapture"]; -	[takeScreenshot setArguments:[NSArray arrayWithObjects:@"-SxC", [supportPath stringByAppendingString:[NSString stringWithFormat:@"/%@.png", date]], nil]]; +	[takeScreenshot setArguments:[NSArray arrayWithObjects:@"-SxC", [applicationSupportPath stringByAppendingString:[NSString stringWithFormat:@"/Screenshots/%@.png", date]], nil]];  	[takeScreenshot launch];  	[takeScreenshot waitUntilExit];  	[takeScreenshot release]; | 
