diff options
| -rw-r--r-- | pywal/export.py | 8 | ||||
| -rw-r--r-- | pywal/wallpaper.py | 29 |
2 files changed, 27 insertions, 10 deletions
diff --git a/pywal/export.py b/pywal/export.py index 1250528..47ea4d2 100644 --- a/pywal/export.py +++ b/pywal/export.py @@ -58,14 +58,18 @@ def template(colors, input_file, output_file=None): # If the color was changed, replace with a unique identifier. if new_color is not colors[cname]: new_color = str(new_color) - new_color_clean = new_color.replace('[', '_').replace(']', '_').replace('.', '_') + new_color_clean = (new_color.replace('[', '_') + .replace(']', '_') + .replace('.', '_')) template_data[i] = l.replace(replace_str, "color" + new_color_clean) colors["color" + new_color_clean] = new_color try: template_data = "".join(template_data).format(**colors) except (ValueError, KeyError, AttributeError) as exc: - logging.error("Syntax error in template file '%s': %r.", input_file, exc) + logging.error( + "Syntax error in template file '%s': %r.", + input_file, exc) return util.save_file(template_data, output_file) diff --git a/pywal/wallpaper.py b/pywal/wallpaper.py index 7d6ae5f..6a50627 100644 --- a/pywal/wallpaper.py +++ b/pywal/wallpaper.py @@ -134,16 +134,29 @@ def set_mac_wallpaper(img): """Set the wallpaper on macOS.""" db_file = "Library/Application Support/Dock/desktoppicture.db" db_path = os.path.join(HOME, db_file) - img_dir, _ = os.path.split(img) - # Clear the existing picture data and write the image paths - sql = "delete from data; " - sql += "insert into data values(\"%s\"); " % img_dir - sql += "insert into data values(\"%s\"); " % img + # Put the image path in the database + sql = "insert into data values(\"%s\"); " % img + subprocess.call(["sqlite3", db_path, sql]) + + # Get the index of the new entry + sql = "select max(rowid) from data;" + new_entry = subprocess.check_output(["sqlite3", db_path, sql]) + new_entry = new_entry.decode('utf8').strip('\n') + + # Get all picture ids (monitor/space pairs) + get_pics_cmd = ['sqlite3', db_path, "select rowid from pictures;"] + pictures = subprocess.check_output(get_pics_cmd) + pictures = pictures.decode('utf8').split('\n') + + # Clear all existing preferences + sql += "delete from preferences; " - # Set all monitors/workspaces to the selected image - sql += "update preferences set data_id=2 where key=1 or key=2 or key=3; " - sql += "update preferences set data_id=1 where key=10 or key=20 or key=30;" + # Write all pictures to the new image + for pic in pictures: + if pic: + sql += 'insert into preferences (key, data_id, picture_id) ' + sql += 'values(1, %s, %s); ' % (new_entry, pic) subprocess.call(["sqlite3", db_path, sql]) |
