Note, that I’m just blindly setting all the screens to the same wallpaper. With these two functions, we can now get and set the wallpapers. And pressing command + control + option + H sets it back again. W, you wallpaper changes to the default.So now when you press command + control + option bind (, "H", function () setWallpaper ( wallpaper ) end ) Now, you can do fun things like this: local wallpaper = "" hs. "/Library/Application Support/Dock/desktoppicture.db" ) for a in connection : rows ( "select value from data limit 1" ) do connection : close () return a end end show ( "Wallpaper Changed" ) end function getWallpaper () local connection = hs. "'" ) connection : close () dock : kill () hs. appFromName ( "Dock" ) connection : exec ( "update data set value = '". "/Library/Application Support/Dock/desktoppicture.db" ) local dock = hs. function setWallpaper ( file ) local connection = hs. Using this, it’s pretty easy to construct a couple of functions that can get and set the wallpapers. Hammerspoon, of course, has SQLite support exposed through the Lua language, which you can access using hs.sqlite3. So, now that we know how to change the wallpaper using SQLite, back to Hammerspoon. It turns out that macOS stores the data about wallpapers in a SQLite database! And, you can literally update this database and change the wallpapers.Īnd now your wallpaper is the default macOS wallpaper. In general, it “works” but it’s a pretty poor solution.īut then I stumbled on this Go program that was the eureka moment. If you have more than one desktop, the script devolves into forcing keystrokes to change to each desktop and then change the wallpaper, which sucks. There are some security hoops you have to jump through to give your script permission through universal access. Many solutions I found were based around this approach, but it has some problems. It turns out you can do this with AppleScript using the osascript command. Since changing the wallpaper is not natively supported in Hammerspoon, I first started looking around for a command line tool that would allow me to change the macOS wallpaper. It serves as a useful visual reference for where you are if you have a dictinct wallpaper that you have at work vs. Today, I want to talk about swapping your wallpapers around. It’s become an indespensible part of my macOS experience. The amount of things that you can do with this tool is pretty stunning. I can do this because I was able to attach a location listener to work’s location, and execute Lua code on arrival. It’s kind of difficult to explain what it does, but the best I can do is that it allows you to use Lua to script actions on your Mac and, crucially, respond to events.įor instance, I use Hammerspoon to lauch all my applications when I get to work and lay them out on the screen in the order that I like.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |