Stop script-initiated desktop wallpaper change from requiring Unlock?

I’ve had this issue for quite a while, can’t remember when it started but could be that it started when I migrated onto a new computer. For some reason difficult to find anything on this via online search.

I’ve got a block that tells Finder to set desktop picture to some file in a given folder.
This all goes smoothly if the script picks an image that it has set as desktop image before, but when it encounters a new one, it opens a pop-up where you have to click “Unlock”. In almost all of my scripts that contain this block, it’s followed by actions that require some application to be frontmost, and this Unlock pop-up messes up the script.

Is there any way to unlock all the images in a folder so I wouldn’t have to keep seeing the Unlock pop-up and just wait for all of the wallpapers in the folder to get set as wallpaper eventually when picked at random?

I tested this and it didn’t do the trick, but then again I’m not even sure if it’s about what I think it is. Because I don’t understand what it means to have to unlock a desktop wallpaper image in such a specific context.

Even something like “IF it asks to unlock, automatically proceed to press return on my behalf” would be better than nothing, but I can’t imagine how I would even address the possible Unlock window.

Operating System: macOS 10.10

Hi.

desktop picture is a legacy item in the Finder. Nowadays, desktop pictures are handled by System Events.

You haven’t said explicitly that the pop-up’s asking you to unlock the picture file, but I’ve assumed here that it is:

tell application "System Events"
	set picturesFolder to pictures folder of current desktop
	set pictureFile to (some file of folder picturesFolder) as alias
end tell

tell application "Finder" to set locked of pictureFile to false -- Just in case it's locked.

tell application "System Events" to set picture of current desktop to pictureFile

-- picturesFolder is returned as a POSIX path, but System Events understands these in its own folder specifiers.
-- System Events can also coerce its own file specifiers to alias and accepts aliases as input.

This seems to yield exactly the same result, I’m afraid.

When it asks to unlock, it displays a column view window displaying the folder level, and then the level where the actual images are in the folder; It has the wallpaper-to-be highlighted from the folder item list so it shows up in the preview column, but all the images in the folder are actually greyed out so you can’t change your mind and manually choose some other image instead.
The window title just says “Unlock” and the available buttons are “Cancel” and “Unlock”.
And I have also checked, if I show info on any of the images in Finder, there are no visible signs of them being locked, which is why I don’t get where this whole business comes from, where does it say that they are and should be unlocked.

…Aaaand while I was finishing writing this response, it gave me an idea: What happens if I manually select the lowest level folder in the wallpaper file path tree instead of try to unlock just the image that it’s trying to use just on that specific cycle of running the applet? Well, that seems to work, which now seems just obvious and logical! To think that I was annoyed by this for about two years and occasional online searches didn’t bring up much.

But I still don’t understand what this unlocking thing was. Can’t remember having seen it after any of the previous Mac migrations, only this most recent one.

Is that form outdated since some later OS than Yosemite?
Because the simple form I mentioned works out fine for me, the Unlock thing was the only annoyance there.

---Change wallpaper
tell application "Finder"
	set desktop picture to some file of folder {"Folder:Here:In:This:Form"}
end tell

Hi.

Yeah. The braces round the path are wrong in any case, but the Finder’s desktop picture has been outdated since at least Leopard (10.5), although presumably it will continue to work until it doesn’t. The equivalent now is:

---Change wallpaper
tell application "System Events"
	set picture of current desktop to some file of folder "Folder:Here:In:This:Form"
end tell

I’ve no idea what can be causing the “Unlock” dialog. I’m not experiencing it myself. It may be some situation on your computer or disk drive rather than a scripting problem. :confused:

Okay, I think I’ll update that syntax to my template files that I use for copy-pasting stuff to new scripts I make, but I have so many old scripts that use that at the moment that, since they do work, I don’t think I’ll go through them all just to change it for now. :cool:

I agree with you, it must be a thing with the disk, and the only way it is a scripting issue is that I only ever encounter it in this one specific context. Hence, I thought that it’s other scripters who might have a small change of having seen it and knowing what it is! It’s pretty unusual not to find anything on a given topic when doing an online search.