Jump to content

Bing Wallpaper


Kennon

Recommended Posts

Author:

I am the author of this workflow.

 

Repository: 

https://github.com/kennonb/alfred-workflow-bing-wallpaper

 

Dependencies:

- PHP

 

Description:

 

This workflow shows the latest 8 wallpapers from Bing Wallpaper. Type bing into Alfred (without any arguments), and it will show you the list of current wallpapers.

 

Then it allows you to:

  • Press Enter to download the wallpaper and set it as your desktop image.
  • Press CMD+Enter to view the wallpaper in your browser.
  • Press Shift, or CMD+Y, to quicklook the image at a reduced resolution.

 

Before you use the workflow you will need to make sure you have PHP installed on your local system. The easiest way is through Homebrew.

  • brew install php

 

Then you will need to configure the path to where you want the wallpapers to be stored on your computer.

 

image.thumb.png.a2c4102ff4682532dff9064418a7907e.png

Edited by Kennon Bickhart
Link to comment
Share on other sites

Pretty detailed submission! Thank you. A few issues:

  • Not really a problem, but you don’t need the if [ -f "/opt/homebrew/bin/php" ] checks (none of the three). Alfred includes all those paths in PATH so you can just php fetchImageList.php "$1" as the whole script (see more).
  • The Default Value for the wallpaperFolder variable should be ~/Photos. Using ~ will let Alfred know to use the correct user directory.
  • The code fails for me:

ERROR: Bing Wallpapers[Script Filter] JSON error: JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0. in JSON:
Warning: Undefined property: stdClass::$desc in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.D3CEBAB3-CF30-4875-B2C4-2AE8C2AB39E6/fetchImageList.php on line 18

Fatal error: Uncaught TypeError: Alfred\Workflows\Item::subtitle(): Argument #1 ($subtitle) must be of type string, null given, called in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.D3CEBAB3-CF30-4875-B2C4-2AE8C2AB39E6/fetchImageList.php on line 18 and defined in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.D3CEBAB3-CF30-4875-B2C4-2AE8C2AB39E6/vendor/joetannenbaum/alfred-workflow/src/ItemParam/HasSubtitle.php:14
Stack trace:
#0 /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.D3CEBAB3-CF30-4875-B2C4-2AE8C2AB39E6/fetchImageList.php(18): Alfred\Workflows\Item->subtitle(NULL)
#1 {main}
  thrown in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.D3CEBAB3-CF30-4875-B2C4-2AE8C2AB39E6/vendor/joetannenbaum/alfred-workflow/src/ItemParam/HasSubtitle.php on line 14

 

Link to comment
Share on other sites

2 hours ago, vitor said:

Pretty detailed submission! Thank you.

 

A few issues:

  • Not really a problem, but you don’t need the if [ -f "/opt/homebrew/bin/php" ] checks (none of the three). Alfred includes all those paths in PATH so you can just php fetchImageList.php "$1" as the whole script (see more).
  • The Default Value for the wallpaperFolder variable should be ~/Photos. Using ~ will let Alfred know to use the correct user directory.
  • The code fails for me:

 

👍🏻

 

1. I've modified that conditional.

2. I've updated the default value for `wallpaperFolder` to `~/Pictures` since that's the default for macOS (I believe, at least it is for me).

3. I added data caching that should automatically invalidate the API data every 2 hours after the initial cache.

 

I can't reproduce that error though. I'm not sure why you'd be getting that. It seems to work just fine for me no matter what I do. 😕 I tried to remove the whole workflow and re-import from scratch and it was still working.

 

Anything else you can think of that I can try to see what you're seeing? What version of everything are you running? I'm on:

 

- PHP 8.2.1

- macOS Ventura 13.2.1

- Macbook Pro 14" M1

 

I've published the changes so far to GitHub.

Link to comment
Share on other sites

On 3/1/2023 at 1:58 AM, Kennon Bickhart said:

What version of everything are you running?

  • PHP 8.2.3
  • macOS 13.2.1
  • M1

The machine is otherwise mostly clean. I can still reproduce with the latest version, though now it’s on line 24 of fetchImageList.php.

Link to comment
Share on other sites

  • 1 month later...

I finally got around to creating a new profile, and installing this workflow. This is what I did.

 

- Create new standard user profile

- Install Alfred 5 from download

- Input power pack license

- Download workflow from Github

- Install workflow

- Init Alfred, and type "bing"

 

Everything just worked. 😕 I'm not sure how else to test this. Maybe in a VM?

Link to comment
Share on other sites

Ok I just installed a completely fresh install of Ventura using Parallels.

 

- Downloaded macOS 13 install image & installed through Parallels Desktop v18.2

- Installed Parallels Tools

- Installed Alfred from website download

- Installed Homebrew from instructions on https://brew.sh

- Installed php with `brew install php`

- Downloaded Bing workflow from GitHub

- Installed workflow

- Init Alfred and typed `bing`

 

I received no errors and everything worked as expected. 🤷🏻‍♂️ I'm definitely at the end of my ability to test now. If you have any other ideas let me know, otherwise I guess I'll just let this one go. 

Link to comment
Share on other sites

I was just thinking about this workflow over the weekend. Nice coincidence that you’ve looked into it again now. I’ve since updated my VM to 13.3 so I gave it another try too.


I still get the error, here’s a fuller version:


[18:41:41.092] Bing Wallpapers[Script Filter] Queuing argument '(null)'
[18:41:41.303] Bing Wallpapers[Script Filter] Script with argv '(null)' finished
[18:41:41.306] ERROR: Bing Wallpapers[Script Filter] Code 255: [Bing Wallpapers] 2023-04-17 19:41:41 Reading from: /Users/vm/Library/Application Support/Alfred/Workflow Data/com.kennonb.alfred-workflow-bing-wallpapers/data.json
[Bing Wallpapers] 2023-04-17 19:41:41 Reading from: /Users/vm/Library/Application Support/Alfred/Workflow Data/com.kennonb.alfred-workflow-bing-wallpapers/data.json
PHP Warning:  Undefined array key "desc" in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.3AB35AC3-514F-48EA-AC28-C997BC74AC91/fetchImageList.php on line 24
PHP Fatal error:  Uncaught TypeError: Alfred\Workflows\Item::subtitle(): Argument #1 ($subtitle) must be of type string, null given, called in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.3AB35AC3-514F-48EA-AC28-C997BC74AC91/fetchImageList.php on line 24 and defined in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.3AB35AC3-514F-48EA-AC28-C997BC74AC91/vendor/joetannenbaum/alfred-workflow/src/ItemParam/HasSubtitle.php:14
Stack trace:
#0 /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.3AB35AC3-514F-48EA-AC28-C997BC74AC91/fetchImageList.php(24): Alfred\Workflows\Item->subtitle(NULL)
#1 {main}
  thrown in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.3AB35AC3-514F-48EA-AC28-C997BC74AC91/vendor/joetannenbaum/alfred-workflow/src/ItemParam/HasSubtitle.php on line 14
[18:41:41.307] Bing Wallpapers[Script Filter] Warning: Undefined array key "desc" in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.3AB35AC3-514F-48EA-AC28-C997BC74AC91/fetchImageList.php on line 24


Fatal error: Uncaught TypeError: Alfred\Workflows\Item::subtitle(): Argument #1 ($subtitle) must be of type string, null given, called in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.3AB35AC3-514F-48EA-AC28-C997BC74AC91/fetchImageList.php on line 24 and defined in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.3AB35AC3-514F-48EA-AC28-C997BC74AC91/vendor/joetannenbaum/alfred-workflow/src/ItemParam/HasSubtitle.php:14
Stack trace:
#0 /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.3AB35AC3-514F-48EA-AC28-C997BC74AC91/fetchImageList.php(24): Alfred\Workflows\Item->subtitle(NULL)
#1 {main}
  thrown in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.3AB35AC3-514F-48EA-AC28-C997BC74AC91/vendor/joetannenbaum/alfred-workflow/src/ItemParam/HasSubtitle.php on line 14
[18:41:41.308] ERROR: Bing Wallpapers[Script Filter] JSON error: JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0. in JSON:
Warning: Undefined array key "desc" in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.3AB35AC3-514F-48EA-AC28-C997BC74AC91/fetchImageList.php on line 24


Fatal error: Uncaught TypeError: Alfred\Workflows\Item::subtitle(): Argument #1 ($subtitle) must be of type string, null given, called in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.3AB35AC3-514F-48EA-AC28-C997BC74AC91/fetchImageList.php on line 24 and defined in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.3AB35AC3-514F-48EA-AC28-C997BC74AC91/vendor/joetannenbaum/alfred-workflow/src/ItemParam/HasSubtitle.php:14
Stack trace:
#0 /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.3AB35AC3-514F-48EA-AC28-C997BC74AC91/fetchImageList.php(24): Alfred\Workflows\Item->subtitle(NULL)
#1 {main}
  thrown in /Users/vm/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.3AB35AC3-514F-48EA-AC28-C997BC74AC91/vendor/joetannenbaum/alfred-workflow/src/ItemParam/HasSubtitle.php on line 14


The problem lies in the attempt to set the subtitle by reading the desc key from the JSON which does not exist. If I set it to a dummy value instead, the workflow works. But then all entries have Info as the image’s title. Here’s what I get right now from querying https://www.bing.com/HPImageArchive.aspx?format=js&n=12&pid=hp&uhd=1&uhdwidth=3840&uhdheight=2160:


{"images":[{"startdate":"20230417","fullstartdate":"202304170700","enddate":"20230418","url":"/th?id=OHR.MinouLighthouse_ROW1985559141_UHD.jpg&rf=LaDigue_UHD.jpg&pid=hp&w=3840&h=2160&rs=1&c=4","urlbase":"/th?id=OHR.MinouLighthouse_ROW1985559141","copyright":"Petit Minou Lighthouse, Plouzané, Brittany, France (© RooM the Agency/Alamy)","copyrightlink":"/search?q=Petit+Minou+Lighthouse&form=hpcapt","title":"Info","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20230417_MinouLighthouse%22&FORM=HPQUIZ","wp":true,"hsh":"5212e422919ffc356a89ce0266506b32","drk":1,"top":1,"bot":1,"hs":[]},{"startdate":"20230416","fullstartdate":"202304160700","enddate":"20230417","url":"/th?id=OHR.KiteDay_ROW1884773634_UHD.jpg&rf=LaDigue_UHD.jpg&pid=hp&w=3840&h=2160&rs=1&c=4","urlbase":"/th?id=OHR.KiteDay_ROW1884773634","copyright":"Adelaide International Kite Festival, Australia (© Andrey Moisseyev/Alamy)","copyrightlink":"/search?q=flying+kites&form=hpcapt","title":"Info","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20230416_KiteDay%22&FORM=HPQUIZ","wp":true,"hsh":"5f38b04d129c1e68c2df95c42f90a0af","drk":1,"top":1,"bot":1,"hs":[]},{"startdate":"20230415","fullstartdate":"202304150700","enddate":"20230416","url":"/th?id=OHR.NahargarhFort_ROW1740335378_UHD.jpg&rf=LaDigue_UHD.jpg&pid=hp&w=3840&h=2160&rs=1&c=4","urlbase":"/th?id=OHR.NahargarhFort_ROW1740335378","copyright":"Aerial view of Jaipur from Nahargarh Fort in Rajasthan, India (© Sean3810/iStock/Getty Images Plus)","copyrightlink":"/search?q=Nahargarh+Fort&form=hpcapt","title":"Info","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20230415_NahargarhFort%22&FORM=HPQUIZ","wp":true,"hsh":"a8b20c93c183158f586f9df952ef5918","drk":1,"top":1,"bot":1,"hs":[]},{"startdate":"20230414","fullstartdate":"202304140700","enddate":"20230415","url":"/th?id=OHR.RedSeaStars_ROW7002802337_UHD.jpg&rf=LaDigue_UHD.jpg&pid=hp&w=3840&h=2160&rs=1&c=4","urlbase":"/th?id=OHR.RedSeaStars_ROW7002802337","copyright":"Red sea stars, Mediterranean Sea (© Hans Leijnse/Minden Pictures)","copyrightlink":"/search?q=sea+star&form=hpcapt","title":"Info","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20230414_RedSeaStars%22&FORM=HPQUIZ","wp":true,"hsh":"fed8957b5827fc692f88560b88db66d9","drk":1,"top":1,"bot":1,"hs":[]},{"startdate":"20230413","fullstartdate":"202304130700","enddate":"20230414","url":"/th?id=OHR.SnowdoniaNational_ROW1485284324_UHD.jpg&rf=LaDigue_UHD.jpg&pid=hp&w=3840&h=2160&rs=1&c=4","urlbase":"/th?id=OHR.SnowdoniaNational_ROW1485284324","copyright":"Snowdonia National Park, Gwynedd, Wales, UK (© Sebastian Wasek/eStock Photo)","copyrightlink":"/search?q=Snowdonia+National+Park&form=hpcapt","title":"Info","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20230413_SnowdoniaNational%22&FORM=HPQUIZ","wp":true,"hsh":"1033d6dc0fc08ee143607967146c1f20","drk":1,"top":1,"bot":1,"hs":[]},{"startdate":"20230412","fullstartdate":"202304120700","enddate":"20230413","url":"/th?id=OHR.EuropeFromISS_ROW1363787892_UHD.jpg&rf=LaDigue_UHD.jpg&pid=hp&w=3840&h=2160&rs=1&c=4","urlbase":"/th?id=OHR.EuropeFromISS_ROW1363787892","copyright":"Earth from the International Space Station (© Tim Peake/ESA/NASA via Getty Images)","copyrightlink":"/search?q=Earth+planet&form=hpcapt","title":"Info","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20230412_EuropeFromISS%22&FORM=HPQUIZ","wp":true,"hsh":"db77e8e34a778b71ed9b80f18070c421","drk":1,"top":1,"bot":1,"hs":[]},{"startdate":"20230411","fullstartdate":"202304110700","enddate":"20230412","url":"/th?id=OHR.MossyGrottoFalls_ROW6376711227_UHD.jpg&rf=LaDigue_UHD.jpg&pid=hp&w=3840&h=2160&rs=1&c=4","urlbase":"/th?id=OHR.MossyGrottoFalls_ROW6376711227","copyright":"Columbia River Gorge, Oregon, USA (© Chase Dekker Wild-Life Images/Getty Images)","copyrightlink":"/search?q=Columbia+River+Gorge+Oregon&form=hpcapt","title":"Info","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20230411_MossyGrottoFalls%22&FORM=HPQUIZ","wp":true,"hsh":"00a6825e186356bf24c98c4e3f0b46bf","drk":1,"top":1,"bot":1,"hs":[]},{"startdate":"20230410","fullstartdate":"202304100700","enddate":"20230411","url":"/th?id=OHR.ElephantTwins_ROW1132340336_UHD.jpg&rf=LaDigue_UHD.jpg&pid=hp&w=3840&h=2160&rs=1&c=4","urlbase":"/th?id=OHR.ElephantTwins_ROW1132340336","copyright":"Elephants in Amboseli National Park, Kenya (© Diana Robinson/Getty Images)","copyrightlink":"/search?q=african+elephants&form=hpcapt","title":"Info","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20230410_ElephantTwins%22&FORM=HPQUIZ","wp":true,"hsh":"168b29229ac24da9dead2ea1cfec6fd9","drk":1,"top":1,"bot":1,"hs":[]}],"tooltips":{"loading":"Loading...","previous":"Previous image","next":"Next image","walle":"This image is not available to download as wallpaper.","walls":"Download this image. Use of this image is restricted to wallpaper only."}}

Link to comment
Share on other sites

Interesting. This is what I get when I hit that same URL. I hadn't ever thought about regional responses, but it appears like Bing gives different responses to different regions via that API. I'm going to check for the existence of description, and title, and default to the date and/or copyright if it doesn't exist. You can try the new version via GitHub now.

 

{
    "images": [
        {
            "startdate": "20230417",
            "fullstartdate": "202304170700",
            "enddate": "20230418",
            "url": "/th?id=OHR.OneThousandSprings_EN-US8092648404_UHD.jpg&rf=LaDigue_UHD.jpg&pid=hp&w=3840&h=1080&rs=1&c=4",
            "urlbase": "/th?id=OHR.OneThousandSprings_EN-US8092648404",
            "copyright": "'One Thousand Springs' haiku art installation by Chiharu Shiota, Kew Royal Botanic Gardens, London, England (© Guy Bell/Alamy Live News)",
            "copyrightlink": "/search?q=royal+botanic+gardens+kew&form=hpcapt&filters=HpDate%3a%2220230417_0700%22",
            "title": "Poetry in suspense",
            "caption": "International Haiku Poetry Day",
            "copyrightonly": "© Guy Bell/Alamy Live News",
            "desc": "Get out your pen and paper—it's International Haiku Poetry Day! Haikus originated in Japan as the opening segment of a larger poem called a renga. Eventually they became individual poems of their own. A traditional haiku consists of 17 phonetic units—similar to a syllable—in a 5, 7, 5 formation. Though simple, a great haiku creates a sense of beauty and a connection to nature. That connection was captured in the artwork seen here, 'One Thousand Springs,' an installation of 5,000 haikus suspended within a web of red threads by artist Chiharu Shiota. It was part of the 2021 Japan Festival at Kew Royal Botanic Gardens in London. Here's some inspiration for you to write a haiku yourself:",
            "date": "Apr 17, 2023",
            "bsTitle": "Poetry in suspense",
            "quiz": "/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20230417_OneThousandSprings%22&FORM=HPQUIZ",
            "wp": false,
            "hsh": "c29c6a484f323dea98b239102ef0e690",
            "drk": 1,
            "top": 1,
            "bot": 1,
            "hs": []
        }
    ],
    "tooltips": {
        "loading": "Loading...",
        "previous": "Previous image",
        "next": "Next image",
        "walle": "This image is not available to download as wallpaper.",
        "walls": "Download this image. Use of this image is restricted to wallpaper only."
    }
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...