diff --git a/build b/build index 00759d9..d8cd000 100755 --- a/build +++ b/build @@ -2,4 +2,4 @@ filename=wallpaper -clang $filename.m -fmodules -mmacosx-version-min=10.6 -o $filename +clang $filename.m -fmodules -mmacosx-version-min=10.6 -lsqlite3 -o $filename diff --git a/wallpaper.m b/wallpaper.m index 38844c4..f30262e 100644 --- a/wallpaper.m +++ b/wallpaper.m @@ -7,6 +7,7 @@ // @import AppKit; +#import int main() { @autoreleasepool { @@ -38,7 +39,41 @@ int main() { return 1; } } else { - printf("%s\n", [sw desktopImageURLForScreen:screen].path.UTF8String); + NSString *url = [sw desktopImageURLForScreen:screen].path; + BOOL isDir; + NSFileManager *fm = [NSFileManager defaultManager]; + + // check if file is a directory + [fm fileExistsAtPath:url isDirectory:&isDir]; + + // if directory, check db + if (isDir) { + NSArray *dirs = [fm URLsForDirectory:NSApplicationSupportDirectory + inDomains:NSUserDomainMask]; + if ([dirs count] > 0) { + NSURL *dbLoc = [[dirs objectAtIndex:0] URLByAppendingPathComponent:@"Dock/desktoppicture.db"]; + const char *dbPath = [[dbLoc path] UTF8String]; + sqlite3 *db = nil; + + if (sqlite3_open(dbPath, &db) == SQLITE_OK) { + sqlite3_stmt *statement; + const char *sql = "SELECT * FROM data"; + + if (sqlite3_prepare_v2(db, sql, -1, &statement, nil) == SQLITE_OK) { + NSString *file; + while (sqlite3_step(statement) == SQLITE_ROW) { + file = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]; + } + + printf("%s/%s\n", url.UTF8String, file.UTF8String); + sqlite3_finalize(statement); + } + sqlite3_close(db); + } + } + } else { + printf("%s\n", url.UTF8String); + } } }