aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2012-07-21 02:14:35 -0400
committerTeddy Wing2012-07-21 02:14:35 -0400
commit0a46e02d9fc2d5671b5454d9c9fe991158c8e304 (patch)
treed67771d6474be5179173835fbbd4ef5b7c064b26
parentf4c76d74ecb66bad371fbf0337c6dbfbe3c8188a (diff)
downloadOn-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.m12
1 files changed, 10 insertions, 2 deletions
diff --git a/On Task.m b/On Task.m
index a4e67e5..5976fa0 100644
--- a/On Task.m
+++ b/On Task.m
@@ -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];