本文介绍了如何获得当前工作区/屏幕的壁纸在OSX上的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自AppKit版本10.7起,可能会返回一个文件夹的路径,而不是当前壁纸的文件的URL。这个文件夹是从哪里的壁纸将被顺序拿起显示的地方。 (在)。

Since AppKit version 10.7, NSWorkspace.desktopImageForScreen may return a path to a folder instead of a file's URL which is currently the wallpaper. This folder is the the place from where the wallpapers will be sequentially picked up for display. (Search for setDesktopImageURL in the release notes).

如果用户将桌面映像设置为每三十分钟左右随机更改,是否有任何方式确定什么是OSX当前活动壁纸每个屏幕?

In case the user has set the desktop image to change randomly every thirty minutes or so, is there any way of determining what are the currently active wallpapers per screen in OSX?

更新:根据@ l'L'l的答案,小型Mac OSX应用程序,方便地找到当前活动的壁纸:

Update: Based no the answer by @l'L'l, I created a small Mac OSX app to conveniently find the currently active Wallpapers: https://github.com/musically-ut/whichbg

推荐答案

OS X 10.10 code> SQLite 3.x数据库名为 desktoppicture.db 。当发生定时随机桌面图片切换或系统偏好设置>桌面有任何更改时,此db文件存储当前桌面图片,目录,空间,间隔等信息:

On OS X 10.10 there is a SQLite 3.x database named desktoppicture.db. This db file stores info such as the current desktop picture, directory, space, interval, etc. when a timed random desktop picture transition happens or when there's any change to System Preferences > Desktop:

// Get Current Desktop Picture

- (IBAction)getDesktopPicture:(id)sender {

    [self getCurrentDesktop];
}

-(void)getCurrentDesktop {

    NSMutableArray *sqliteData = [[NSMutableArray alloc] init];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
    NSString *appSup = [paths firstObject];
    NSString *dbPath = [appSup stringByAppendingPathComponent:@"Dock/desktoppicture.db"];

    sqlite3 *database;
    if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {

        const char *sql = "SELECT * FROM data";
        sqlite3_stmt *sel;
        if(sqlite3_prepare_v2(database, sql, -1, &sel, NULL) == SQLITE_OK) {

            while(sqlite3_step(sel) == SQLITE_ROW) {
                NSString *data = [NSString stringWithUTF8String:(char *)sqlite3_column_text(sel, 0)];
                [sqliteData addObject:data];
            }
        }
    }
    NSUInteger cnt = [sqliteData count] - 1;
    NSLog(@"Desktop Picture: %@", sqliteData[cnt]);
    NSLog(@"%@",sqliteData);

    sqlite3_close(database); 
}

结果:

2015-06-23 14:36:04.470 CurrentDesktop [72591:87862519]桌面
图片:Poppies.jpg 2015-06-23 14:36:04.470
CurrentDesktop [ 72591:87862519](
60.0,
1,
Poppies.jpg)

有很多不同的其他方法可以从这个文件中获取数据(例如 NSTask Bash AppleScript 等。这是我首选的解决方案,因为它是本地的Mac代码;它足够简单,以便为其他的东西可移植。

There are quite a few different other ways you can get the data from this file (eg. NSTask, Bash, AppleScript, etc. This is my preferred solution since it's native mac code; it's simple enough to make portable for something else though.

这篇关于如何获得当前工作区/屏幕的壁纸在OSX上的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 04:44