Skip to content

Conversation

@arebee
Copy link

@arebee arebee commented Jul 21, 2025

Here's some changes to support

  1. MacOS and other non-Windows OSs.
  2. Support for paged results up to 15 images (seems to be the limit based on the API)

Use it for parts if you wish.

Copy link
Owner

@timothymctim timothymctim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your pull request! I’ve reformatted the code in another commit so that your contributions won’t be cluttered by formatting. I hope you can address the few questions I have before merging your code.

}
[string]$hostname = "https://www.bing.com"
[string]$uri = "$hostname/HPImageArchive.aspx?format=xml&idx=0&n=$maxItemCount$market"
[string]$uri = "$hostname/HPImageArchive.aspx?format=xml$market&pid=hp"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, I cannot get this URL to work for me, the n parameter really seems required for me and the pid=hp parameter and value does not seem to add anything for me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can repro. Sorry. Looks like the bare URL just needs the n path parameter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I yanked this when using the non-official URL. My experiments on this path indicate that only n= is honored.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the URL gets added to below in the request paging logic.

$null, $items = $items
if ($files -gt 0) {
if ($useJsonSource) {
$jsonImgs = ConvertFrom-Json -InputObject $(Invoke-WebRequest -Uri 'https://api45gabs.azurewebsites.net/api/sample/bingphotos')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I’m not mistaken, this endpoint is not an official one. I’m therefore hesitant to include it in this script. If you can find an ‘official’ endpoint that we could use, that would be perfect!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't see one and the history on the "official" endpoint is short.
Completely your call if you want to add this.

$resolution = '1920x1200'
}
}
else {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not that familiar with PowerShell on non-Windows systems, but don’t they have a way to get the screen resolution either?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not using Windows specific classes. I will add a way for determining this for MacOS in a seperate PR


# Download the latest $files wallpapers
# Download the latest $files wallpapers.
[ValidateRange("Positive")]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[ValidateRange("Positive")]
[ValidateRange("NonNegative")]

files could also be set to 0, NonNegative is required. From the PowerShell 7.4 documentation:

Positive - A number greater than zero.
NonNegative - A number greater than or equal to zero.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would someone want to download 0 wallpapers? That doesn't make much sense to me.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants