Last active
March 26, 2016 14:06
-
-
Save hideyukisaito/52afb32092e619e15e52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
auto main() -> int | |
{ | |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
NSURL *basePath = [NSURL URLWithString:@"path/to/directory"]; | |
NSFileManager *fm = [NSFileManager defaultManager]; | |
NSArray<NSString *> *files = [fm contentsOfDirectoryAtPath:[basePath absoluteString] error:nil]; | |
if (0 < [files count]) | |
{ | |
NSWorkspace *ws = [NSWorkspace sharedWorkspace]; | |
NSURL *imageURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", [basePath absoluteString], files[0]] isDirectory:NO]; | |
NSError *error; | |
BOOL success = [ws setDesktopImageURL:imageURL forScreen:[NSScreen mainScreen] options:nil error:&error]; | |
if (!success) | |
{ | |
std::cout << [[error localizedDescription] UTF8String] << std::endl; | |
} | |
} | |
[pool release]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment