Skip to content

Instantly share code, notes, and snippets.

@hideyukisaito
Last active March 26, 2016 14:06
Show Gist options
  • Save hideyukisaito/52afb32092e619e15e52 to your computer and use it in GitHub Desktop.
Save hideyukisaito/52afb32092e619e15e52 to your computer and use it in GitHub Desktop.
#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