我正在尝试制作一个applescript,让我将桌面图片更改为硬盘驱动器文件夹中的随机图片
tell application "Finder"
set desktopPictures to folder "Path:To:Desktop:Pictures:"
set fileList to name of every file of desktopPictures
set theNum to random number from 1 to (count fileList) with seed ((time of (current date)) * 4)
set fileName to item theNum of fileList
set desktop picture to file fileName in desktopPictures
end tell
到目前为止,它运行良好,唯一的问题是当我连接另一台显示器时,他的桌面图像不会改变。我尝试使用以下发现进行网络搜索的代码解决此问题
tell application "Finder"
set desktopPictures to folder "Path:To:Desktop:Pictures:"
set fileList to name of every file of desktopPictures
set theDesktops to a reference to every desktop
repeat with aDesktop in theDesktops
set theNum to random number from 1 to (count fileList) with seed ((time of (current date)) * 4)
set fileName to item theNum of fileList
set picture of aDesktop to file fileName in desktopPictures
end repeat
end tell
但是由于出现语法错误,因此无法编译此代码:
Expected class name but found property.
凭借desktop
突出显示4行
您从找到的代码中省略了Tell应用程序“ System Events”块。
在Applescript中,某些命令存在于特定应用程序的字典中,并且必须用“ tell application”块引用。在这种情况下,“每个桌面”调用都在“系统事件”应用程序中。
尝试这个。
tell application "Finder"
set desktopPictures to folder "Path:To:Desktop:Pictures:"
set fileList to name of every file of desktopPictures
tell application "System Events"
set theDesktops to a reference to every desktop
end tell
repeat with aDesktop in theDesktops
set theNum to random number from 1 to (count fileList) with seed ((time of (current date)) * 4)
set fileName to item theNum of fileList
set picture of aDesktop to file fileName in desktopPictures
end repeat
end tell
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句