我今天自己遇到了这个问题,并进行了一些反向工程。因此,实际上有
4个关键步骤可以实现您想要的功能:
Clear the entire database. (This is not mandatory but makes everything much easier)
DELETE FROM data
DELETE FROM displays;
DELETE FROM pictures;
DELETE FROM preferences;
DELETE FROM prefs;
DELETE FROM spaces;
Add an empty row to the pictures
table. As far as I understood it, this somehow works as a fallback and macOS automatically creates additional rows with according display IDs and space IDs based on everything we define now.
INSERT INTO pictures (space_id, display_id) VALUES (null, null);
Add your actual preferences to the data
table.
INSERT INTO data (value) VALUES ('~/Pictures');
INSERT INTO data (value) VALUES (60);
INSERT INTO data (value) VALUES (5);
INSERT INTO data (value) VALUES (0.07);
INSERT INTO data (value) VALUES ('current-wallpaper.jpg');
INSERT INTO data (value) VALUES (1);
Now this is the most important part — the actual mapping of the data with the appropriate macOS internal preferences keys. This is what I found out so far:
#1: Image path
#2: Scaling method (Fill Screen (1), Center (3), Stretch to Fill Screen (4), Fit to Screen (5))
#3: Fill color
#4: Fill color
#5: Fill color
#9: Enable automatic changing
#10: Directory path to images
#11: Image changing interval
#12: Random order
#16: Current image (used when automatic changing is enabled)
So all you have to do is to match the IDs of the data rows with the keys listed above. For example
INSERT INTO preferences (key, data_id, picture_id) VALUES (11, 2, 1);
The line above means: Use the 2nd row from the data
table (→ 60) as the Image changing interval
(#11) for the 1st picture (which in our case means all spaces/displays by default).
在我的情况下,我想要每隔一分钟更换壁纸,从一个特定文件夹中随机选择图片并启用适应屏幕功能和7%亮度的黑色背景颜色。我使用以下代码实现:
sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db " \
DELETE FROM data; \
DELETE FROM displays; \
DELETE FROM pictures; \
DELETE FROM preferences; \
DELETE FROM prefs; \
DELETE FROM spaces; \
INSERT INTO pictures (space_id, display_id) VALUES (null, null); \
INSERT INTO data (value) VALUES ('~/Pictures'); \
INSERT INTO data (value) VALUES (60); \
INSERT INTO data (value) VALUES (5); \
INSERT INTO data (value) VALUES (0.07); \
INSERT INTO data (value) VALUES ('198.png'); \
INSERT INTO data (value) VALUES (1); \
INSERT INTO preferences (key, data_id, picture_id) VALUES (2, 3, 1); \
INSERT INTO preferences (key, data_id, picture_id) VALUES (3, 4, 1); \
INSERT INTO preferences (key, data_id, picture_id) VALUES (4, 4, 1); \
INSERT INTO preferences (key, data_id, picture_id) VALUES (5, 4, 1); \
INSERT INTO preferences (key, data_id, picture_id) VALUES (9, 6, 1); \
INSERT INTO preferences (key, data_id, picture_id) VALUES (10, 1, 1); \
INSERT INTO preferences (key, data_id, picture_id) VALUES (11, 2, 1); \
INSERT INTO preferences (key, data_id, picture_id) VALUES (12, 6, 1); \
INSERT INTO preferences (key, data_id, picture_id) VALUES (16, 5, 1); \
" && killall Dock
希望这能帮助那些在IT技术方面困惑的人。