-- get list of pics
set theURL to current application's NSURL's fileURLWithPath_("/Library/Desktop Pictures")
set theFileManager to current application's NSFileManager's alloc()'s init()
set theURLs to theFileManager's contentsOfDirectoryAtURL_includingPropertiesForKeys_options_error_(theURL, missing value, 7, missing value) as list
set theWorkspace to current application's NSWorkspace's sharedWorkspace()
-- get list of screens
set theScreens to current application's NSScreen's screens() as list
repeat with i from 1 to count of theScreens
repeat -- keep repeating if file is not .jpg or .png
set aPic to some item of theURLs
if (aPic's pathExtension() as text) is in {"jpg", "png"} then
exit repeat
end if
end repeat
-- change the pic
tell theWorkspace to setDesktopImageURL_forScreen_options_error_(aPic, item i of theScreens, missing value, missing value)
end repeat