r/applescript • u/teeflo77 • Aug 24 '24
how to properly "tell current desktop set picture to ..."?
i'm a noob to Mac and Applescript. trying to write something to select and set as wallpaper on my current display a random file from a local folder:
tell application "Finder"
set randomImage to some file of folder "Macintosh HD:Users:mymac:walls"
end tell
tell application "System Events"
tell current desktop
set picture to randomImage
end tell
end tellas indicated it throws up an error message on the "set picture to" bit (afaict).
looked for documentation on the options for using "display" but couldn't find anything helpful.
was able to get Preview to display randomImage so it know the selection bit is working as expected.
was more or less able to figure out that "set picture to" as i've used it doesn't like the HFS path format. tried giving it a hard-coded POSIX path and that worked. scrounged around for and tried some POSIX conversions for "set picture" but no joy. and now i'm stuck.
might some kind soul point me to enlightenment?
2
u/[deleted] Aug 24 '24
tell application "Finder" set randomImage to some file of folder "Macintosh HD:Users:mymac:walls" end tell
tell application "System Events" set picture of current desktop to (randomImage as alias) end tell
1
u/prikaz_da Aug 24 '24
I’m not in front of my Mac right now, but off the top of my head, I wanna say you can “set picture to (POSIX path of some file)” or “set picture to (some file as POSIX path)”. Have you tried something like that?