Git Product home page Git Product logo

wallpaper's Introduction

wallpaper

Get or set the desktop wallpaper

Works on macOS 10.14.4+, Linux, and Windows 10+.

Maintainer needed for the Linux part of the code. No new Linux-related changes will be accepted until someone with good Linux knowledge volunteers.

Install

npm install wallpaper

Usage

import {getWallpaper, setWallpaper} from 'wallpaper';

await setWallpaper('unicorn.jpg');

await getWallpaper();
//=> '/Users/sindresorhus/unicorn.jpg'

API

getWallpaper(options?)

Returns a Promise<string> with the path of the current desktop wallpaper.

options

Type: object

screen (macOS only)

Type: string | number
Values: 'all', 'main', or the index of a screen from .screens()
Default: 'main'

The screen to get the wallpaper from.

If you set 'all' then getWallpaper() will return a Promise<string[]>.

setWallpaper(imagePath, options?)

Returns a Promise.

On macOS, it sets the wallpaper on the active space. There is no way to set it on all spaces.

imagePath

Type: string

The path to the image to set as the desktop wallpaper.

options

Type: object

screen (macOS only)

Type: string | number
Values: 'all', 'main', or the index of a screen from .screens() Default: 'all'

The screen to set the wallpaper on.

On Linux and Windows it's hard-coded to 'main'.

scale (macOS & Windows)

Type: string
macOS Values: 'auto' | 'fill' | 'fit' | 'stretch' | 'center'
Windows Values: 'center' | 'stretch' | 'tile' | 'span' | 'fit' | 'fill'
Default macOS: 'auto'
Default Windows: 'span'

Scaling method.

setSolidColorWallpaper(color, options?) (macOS only)

Returns a Promise.

color

Type: string

The color to set as a RGB Hex value. For example, 000000 for black.

options

Type: object

screen

Type: string | number
Values: 'all', 'main', or the index of a screen from .screens() Default: 'all'

The screen to set the wallpaper on.

import {setSolidColorWallpaper} from 'wallpaper';

await setSolidColorWallpaper('000000');

screens() (macOS only)

Returns a Promise<string[]> with the available screens.

import {screens} from 'wallpaper';

await screens();
//=> ['Color LCD']

FAQ

How can I set a website as a static wallpaper?

If you only need a static snapshot of the website, you can use capture-website and then pass the result to this package. You can make it semi-dynamic, by capturing the website snapshot every 10 seconds, for example.

How can I set a website, video, or WebGL as a dynamic wallpaper?

You cannot use this package to set a dynamic wallpaper.

On macOS, check out Plash, which lets you set any website as your wallpaper. The website could contain a fullscreen video, WebGL, slideshow, animated, etc.

You can also do this with Electron on macOS and Linux by using new BrowserWindow({type: 'desktop'}).

On Windows, you can use Wallpaper Engine. It's available on Steam, HumbleBundle, and Green Man Gaming for around 4 USD.

Related

wallpaper's People

Contributors

bendingbender avatar beyluta avatar codetheweb avatar doannc2212 avatar fa7ad avatar fedemp avatar giftia avatar maxanier avatar moritzruth avatar pierre-monier avatar rafi993 avatar richienb avatar samverschueren avatar sindresorhus avatar sonicdoe avatar tiagodanin avatar vardanheroic avatar victorioberra avatar xero08 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wallpaper's Issues

Image set on windows 10 are not permanent, Once rebooted new image is lost

Hi,

I've made a simple program that uses https://www.npmjs.com/package/wallpaper to change the desktop wallapaper, eventhough the change is perfomed from the app, meaning, I see the desptop reflecting the change (showing the new desktop background) once I reboot the desktop wallpeper is reverted to wharever imageIi had before the change.

I know that people will start to say that this is not an issue on the wallpaper module, and it's more likely a Windows issue. Let me say, For sure windows is also to blame here, alter build #1803 a lot of sh... stared to heppen, so, in order to velidate that theory I've used Microsoft tutorial on how to change desktop wallpapers, I've follow the guidance and compiled a small c++ program, Using this program all changes are permanent regardless of the reboot or not. So clearly there is something wrong with this code when used on windows 10 version #1803.

Regards

Error: spawn /macos-wallpaper ENOENT

Hi,
When I use every method of this library like wallpaper.get() I get this error:

Uncaught (in promise) Error: spawn /macos-wallpaper ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:229)
    at onErrorNT (internal/child_process.js:406)
    at process._tickCallback (internal/process/next_tick.js:63)

I checked out #30 but it didn't work for me.

note:
When I run console.log(process.platform) from all over the application return darwin.

os: macOS High Sierra 10.13.4
node: 10.12.0
npm: 6.4.1
electron v3.0.5
wallpaper: ^4.1.0
wallpaper-cli: ^2.0.0

Wallaper Setting In Android

Hope We Can Have Intent.ACTION_SET_WALLPAPER In React Native.
There are no modules out there with this functionality.

I searched a lot on google but couldn't find any solution to set wallpaper in react native
but came across intent and found solutions like the one's below

    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setDataAndType(uri, "image/jpeg");
    intent.putExtra("mimeType", "image/jpeg");
    this.startActivity(Intent.createChooser(intent, "Set as:"));
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(Intent.createChooser(intent, "Select Wallpaper"));

There are Mostly Unanswered Questions In Stackoverflow

https://stackoverflow.com/questions/18700161/android-set-wallpaper-using-intent

If I set the wallpaper twice in a row with the same image, it removes the wallpaper the second time

If I set the wallpaper twice, the second time it will remove the wallpaper and set it to the default desktop wallpaper. The issue is, I can't rely on get to tell me that the wallpaper is correctly set. When the wallpaper is changed back to default, get still returns the wallpaper I set initially. In fact, on MacOS settings, it still shows the correct wallpaper. My program is setting the wallpaper every 24 hours, but it has to be able to reliably recover from a crash, waking from sleep, and timezone shifts. So what I want to do is be able to check if the wallpaper that is currently set is the correct one, and if not, change it. However, because I can't rely on get to do that, I'm not sure what to do.

Am I doing something wrong here? I've tried this on multiple computers and am running into this issue consistently. Maybe there's a good way to work around this limitation?

This is what it looks like if you're running it from the CLI:

// Set the wallpaper
$ /macos-wallpaper set ~/Pictures/wallpaper.jpg --screen all --scale auto
// Wallpaper gets set to this image

// Get the wallpaper
$ /macos-wallpaper get
// Correct image is returned
/wallpaper.jpg

// Run a second set
$ /macos-wallpaper set ~/Pictures/wallpaper.jpg --screen all --scale auto
// Wallpaper now becomes default desktop

// Get the wallpaper again
$ /macos-wallpaper get
// The image I set earlier is returned, even though the desktop is showing the default wallpaper
/wallpaper.jpg

Here's a gif that shows the issue:
CleanShot 2020-07-14 at 18 48 31

Help wanted with Linux part of the code

Looking for someone experienced with Linux and JS that can help out. I'm tired of handling low-quality Linux-related PRs. I don't even use Linux and there are just too many edge-cases.

cp.exec is not a function

I get the following error when launching the wallpaper.get() function to retrieve the path of the current background image inside my components. It works from the electron process. Is it problematic that the linux.js is used even though I am on windows 10 at the moment?

grafik

Default wallpaper is shown for ≈0.5 sec

Issuehunt badges

When calling wallpaper.set('img/artwork.png') in a node app running on Mojave, the default wallpaper (not set via this API) is shown for approximately 0.5 sec. Is this a known issue? If so: any ways to get around it? Thanks.

There is a $60.00 open bounty on this issue. Add more on Issuehunt.

[Mac os] Set wallpaper on all spaces

Hello,
Thank you very much for this package! It helps me a lot for a project.
But i have a little suggestion for improvement.
Is it possible to put an image as wallpaper on all spaces with mac os?

Thank you !

Crashes on GNOME

I get this error when I run

wallpaper.get().then(console.log)

Error:

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Command failed: gsettings get org.cinnamon.desktop.background picture-uri
No such schema 'org.cinnamon.desktop.background'

First I thought it was a bug on my fork, so I tried pulling from your repo, and then I tried installing the package from npm again. Same problem, my guess is that the command for Cinnamon somehow replaces the command for GNOME (probably because they both use gsettings).

Setting wallpaper through an Electron app, switches back *after* changing window focus

I'm building a little Electron app that runs in the tray and changes the wallpaper. While it does this reliably, the wallpaper changes back if any other window takes focus. Can't figure out why or how this could be happening. I would assume once the wallpaper is changed, that it wouldn't change back.

I have this function doing the heavy lifting in main.js:

exports.setAsBackground = (imageUrl) => {
  const imageName = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
  const filePath = path.join(app.getPath('pictures'), imageName);
  download(imageUrl)
    .then(data => {
      fs.writeFileSync(filePath, data);
    })
    .then(() => {
      wallpaper.set(filePath);
    })
    .catch(err => {
      console.log(err);
    });
}

This gets called from the renderer, passing in whatever URL:

const { remote } = require("electron");
const mainProcess = remote.require("./main.js");

mainProcess.setAsBackground(
  "https://ids.lib.harvard.edu/ids/iiif/18483392/full/full/0/default.jpg"
);

This all seems pretty straightforward. And, indeed, it reliably downloads the file and sets the wallpaper. However, as soon as I click on another window and it takes focus, the wallpaper switches back the what it was originally. I cannot find a single thing about this kind of behavior online and I can't really wrap my head around what is happening.

Is there anything obvious I'm missing?

set wallpaper doesn't work

My script looks like this:

wallpaper.set(fullImagePath).then(() => {
  console.log('Set as wallpaper')
  wallpaper.get().then(imagePath => {
       console.log(`Current wallpaper: ${imagePath}`)
  })
})

which is run by crontab on Ubuntu 16.04 (with GNOME).
The wallpaper doesn't change, and the logged imagePath does not equal fullImagePath.
The output was like:

Image already downloaded at: /home/doma/scripts/bing-wallpaper-script/downloads/20170605.jpg
Set as wallpaper
Current wallpaper: /usr/share/backgrounds/warty-final-ubuntu.png

However when I run this script manually (not invoke by crontab), it works fine.

spawn (hardcoded)/macos-wallpaper ENOENT

Hello, using

  • electron (17.1.2) and
  • wallpaper (6.1.1)

When building dist with electron builder and running the app - the path to macos-wallpaper is for some reason hardcoded to the path of the local project of the device on which it was building.

The problem is the same with asar false and I tried to manually include wallpaper lib in dist and reference it in the project - it works locally but not after the build again.

I didn't even notice this before trying to run the app on another device where there is no locally saved dev directory with macos-wallpaper lib in the same place.

import { screens } from "wallpaper";
// ...
const currentMonitors = await screens();

Sentry error after running the build

Error
spawn /Users/bumtomica/Development/splashy-desktop/dist/wallpaper/source/macos-wallpaper ENOENT
// or
spawn /Users/bumtomica/Development/splashy-desktop/node_modules/wallpaper/source/macos-wallpaper ENOENT

Not sure if I'm doing something wrong with init or build, please advise.

Failed to set the desktop wallpaper

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Command failed: E:\new Object\node\small\getpic\node_modules_wallpaper@2.5.0@wallpaper\lib\win-wallpaper.exe E:\new Object\node\small\getpic\RoyalAlcazars_EN-AU13378849776.png

this is the error message. i have the picture

Windows group policies

Hi, will this able to change the wallpaper even admin disabled the changing wallpapers through Windows group policies? I m looking for that since sometime.

My idea is to show some blank canvas beneath all the icons on the desktop and apply image to that canvas. But I m not sure how to do that. I only know Java & JavaScript :)

Thanks.

Problems setting wallpaper from cron or as sudo

When invoking simple script that should change wallpaper with sudo ie: sudo /abs/path/script.js or from cron * * * * * /abs/path/script.js wallpaper stays the same. When called manually and without sudo/cron it works as intended.

Any ideas what might be wrong?

Failed to set wallpaper on linux mint cinnamon

Thank you for this package and I hope you can fix this bug. I don't know much about kde and stuff so I can't be helpful in the issue. This is the error that I'm receiving:

Uncaught (in promise) Error: Command failed: qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript 
				var allDesktops = desktops();
				for (var i = 0; i < allDesktops.length; i++) {
					var desktop = allDesktops[i];
					desktop.wallpaperPlugin = 'org.kde.image';
					desktop.currentConfigGroup = ['Wallpaper', 'org.kde.image', 'General'];
					desktop.writeConfig('Image', '{hidden_image_path}');
				}
			
Cannot find 'org.kde.PlasmaShell.evaluateScript' in object /PlasmaShell at org.kde.plasmashell

I'm on Linux mint 18.2 cinnamon 64bit. Cinnamon version: 3.4.3

Cant set wallpaper from url

i want to set wallpaper from a url like
wallpaper.set("ImAgeurl.jpg").then(() => { });
but it dosent work and desktop wallpaper goes black

Problems in Setting With Nodejs 16

Im Using Quasar FrameWork With Vue 3

and I Get This

 App •  ERROR  •  Renderer  in node:path

UnhandledSchemeError: Reading from "node:path" is not handled by plugins (Unhandled scheme)  .
  Webpack supports "data:" and "file:" URIs by default.
  You may need an additional plugin to handle "node:" URIs.

Scaling on Linux

on linux when setting wallpaper using wallpaper.set(path, {scale: blabla}) scale option seems to be not working.

Cross Fade to another image - possible?

When invoking, for example,

wallpaper.set('unicorn.jpg');

is it possible to make it so the wallpaper crossfade to another image, not just instantly change?

Error setting images as wallpaper in Windows

Under Windows 7 I have errors when configuring images as wallpaper. Mostly with png files but also with some jpg.
With a png image.
Trace:
Error: Command failed: ./wallpaper.exe C:\Users\myuser\Pictures\walls\zohk0p38npend5mulxkm.png
Failed to set the desktop wallpaper
at ChildProcess.exithandler (child_process.js:751:12)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Socket. (child_process.js:1183:11)
at Socket.emit (events.js:107:17)
at Pipe.close (net.js:485:12)

With a jpg image.
Error: Command failed: ./wallpaper.exe C:\Users\myuser\Pictures\walls\05-11-2010.jpg
Failed to set the desktop wallpaper
at ChildProcess.exithandler (child_process.js:751:12)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Socket. (child_process.js:1183:11)
at Socket.emit (events.js:107:17)
at Pipe.close (net.js:485:12)

Setting background color

Hello,

Is there a way to set the background color behind the image?
This is useful on macOs which has a blue background by default behind the wallpaper which shows up if the image is not large enough.

Thank you!

Example Error

Running your example:

const wallpaper = require('wallpaper');

wallpaper.set('unicorn.jpg').then(() => {
    console.log('done');
});

wallpaper.get().then(imagePath => {
    console.log(imagePath);
    //=> '/Users/sindresorhus/unicorn.jpg'
});

On Linux Ubuntu throws an error on /lib/linux.js:

return cp.execFile(app.cmd, app.get).then(stdout => 

TypeError: Cannot read property 'cmd' of undefined

Seems to be due to using async functions (get and set) at the same time (same problem with different error if using get before set

The problem solves simply using the second command inside the callback:

const wallpaper = require('wallpaper');

wallpaper.set('unicorn.jpg').then(() => {
    console.log('done');
    wallpaper.get().then(imagePath => {
        console.log(imagePath);
        //=> '/Users/sindresorhus/unicorn.jpg'
    });
});

I'm not sure if the problem is just in linux, and if its an error in the example code or in the linux library.

Feature Proposal: Control over get method

What do you think about optional "environment" names?
One way to make sure the correct flags are used when the command is same but he environment is different.

Example:

wallpaper.get().then(console.log) // behaves normally (current behaviour)

wallpaper.get('cinnamon').then(console.log) // tries only the command for cinnamon and nothing else

This could be also be useful for people that use multiple Desktop Environments / Tools. Plus, it would be an "easy" way to fix #18 AND avoid future problems like this

Use website as wallpaper?

Hi there!

Is there a solution to set a website as a wallpaper os mac os?

I've seen some solutions on ProductHunt but none of them still work or are maintained.

In my company, we have a dashboard with all our business metrics - it is hosted in the private VPN network. We want to see all of these numbers on our wallpaper on our laptops. Is there a solution of that?

Gnome caching

Hi. I was using your package and suddenly it seemed to have stopped working, it's not really a bug though (Linux).

I am using elementaryOS (Ubuntu) and gsettings set picture-uri seems to be caching wallpapers/paths and does not update the wallpaper if a same path is used (I was changing wallpapers every x seconds with the same name in one folder). It doesn't fail, and doesn't give any errors, I'm not too certain how well-known this knowledge is but maybe it is worth mentioning in a readme section? Once you know this it's easy enough to generate random names.

Alternative, something like clearing cache might work? But, this isn't best practice I guess?

Edit^: cache is maybe a bit a wrong explanation/terminology. The path image-uri gets set but wallpaper (when same path) does not update until reboot.

Or, maybe something like wallpaper.set => "get > set > get > if is the same give warning". Although, it might not be the package it's responsibly.

Thanks for all your work!

MacOS Mojave

Hey there,

I've updated my macOS to Mojave, and I'm getting this error while trying to perform wallpaper.get():

Wallpaper error Error: spawn /macos-wallpaper ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:229)
    at onErrorNT (internal/child_process.js:406)
    at process._tickCallback (internal/process/next_tick.js:63)

Is there any known cause of this?

Error when importing wallpaper

I am getting an error when importing wallpaper to my project:

TypeError: The "original" argument must be of type Function

It seems the promisify function in the util library it is referencing. I've tried only using the macos files and importing locally using other promisify packages, but they resulted in other errors.

Is it because of the version of the util library? According to where the error pointed to me, I'm using 0.11.1

OS: macOS 10.15.3
Node: 10.16.0
npm 6.13.1

Anyone got a solution? Thanks!

Support screen options

OS X has the following options:

  • Fill Screen
  • Fit to Screen
  • Stretch to Fill Screen
  • Center
  • Tile

Real time Wegl animation ?

Hello,
Is it possible to make dynamic wallpaper ?

It possible to integrate webgl framework like pixi.js ?

Thanks

KDE/Plasma not working.

Tested with Arch and Kubuntu, no errors. When I run the command from desktop-managers/qdbus.js it works:

qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript 'var allDesktops = desktops(); for (var i = 0; i < allDesktops.length; i++) { var desktop = allDesktops[i]; desktop.wallpaperPlugin = "org.kde.image"; desktop.currentConfigGroup = ["Wallpaper", "org.kde.image", "General"]; desktop.writeConfig("Image", "file://home/tory/Pictures/image.png"); }'

But for some reason it does not work when this module calls it.

Support for multiple screens on Windows

Hi,

I'm wondering how do you handle multiscreen configuration ?
Are you setting the same image on different screen or can you assign an image as a wallpaper for a particular screen (or desktop in case of osx).

I can identify 3 use-cases :

  • Set genericWallpaper.jpg to screen all screen A,B,C
  • Set panoramicWallpaper.jpg to be a single image covering screen A,B,C
  • Set wallA.jpg and wallB.jpg to respectively cover screen A and B

When I import from 'wallpaper'

Being on Windows and Linux: Debian Bulleye
./node_modules/wallpaper/source/linux/util.js
Module not found: Can't resolve 'node:child_process' in '[project-dir]\node_modules\wallpaper\source\linux'

I am having an issue when i set the wallpaper from electron app

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Command failed: D:\ionic\demos\electron\electron-tutorial\node_mo
dules\wallpaper\lib\win-wallpaper.exe D:\ionic\demos\electron\electron-tutorial\google.png
Failed to set the desktop wallpaper
(node:2432) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js proces
s with a non-zero exit code.

I have the google.png image in my path but it's still not setting the wallpaper but generating an error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.