Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable automatic changing of wallpaper image #24

Open
jessemillar opened this issue Mar 15, 2019 · 4 comments
Open

Disable automatic changing of wallpaper image #24

jessemillar opened this issue Mar 15, 2019 · 4 comments

Comments

@jessemillar
Copy link

jessemillar commented Mar 15, 2019

When I set my wallpaper using wallpaper to a directory instead of an image (e.g. wallpaper set ~/.trunk/wallpaper/desktop), it automatically checks the "Change picture every X minutes" checkbox. This does not happen when I set the wallpaper to a specific file (e.g. wallpaper set ~/.trunk/wallpaper/desktop/foggy-trees.jpg). Is this an Apple-imposed limitation? Or could there be a CLI flag that allows me to disable that functionality?

Screen Shot 2019-03-15 at 11 39 06 AM

@sindresorhus
Copy link
Owner

What's the point of setting it to a directory if you don't want it to change automatically?

@jessemillar
Copy link
Author

I have a manual script setup that runs periodically to change the wallpaper in response to system events. I'd rather not have it change randomly on me via the OS.

@sindresorhus
Copy link
Owner

There's no macOS API to control this behavior. It's just happens when we pass a directory as wallpaper.

try NSWorkspace.shared.setDesktopImageURL(image, for: nsScreen, options: options)

One solution could be to programmatically change that system preference after setting the directory as wallpaper.

The setting might also be stored in the wallpaper database, not sure, which we do have access to:

/// Works around macOS bug where it sometimes returns a directory instead of an image.
/// https://openradar.appspot.com/radar?id=4959084113559552
private static func getFromDirectory(_ url: URL) throws -> URL {
let appSupportDirectory = try FileManager.default.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
let dbURL = appSupportDirectory.appendingPathComponent("Dock/desktoppicture.db")
let table = Table("data")
let column = Expression<String>("value")
let rowID = Expression<Int64>("rowid")
let db = try Connection(dbURL.path)
let maxID = try db.scalar(table.select(rowID.max))!
let query = table.select(column).filter(rowID == maxID)
let image = try db.pluck(query)!.get(column)
return url.appendingPathComponent(image)
}

@boettchs
Copy link

HI, cool tool!
Wondering if you can change the duration of the rotation? My test Mac sets at 30 mins, but I'd like to save it to 8 hours or on login, etc?

Thanks much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants