1

我正在尝试制作一个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 行突出显示

4

1 回答 1

1

您从找到的代码中省略了告诉应用程序“系统事件”块。

在 Applescript 中,某些命令存在于特定应用程序的字典中,并且必须使用“告诉应用程序”块来引用。在这种情况下,“每个桌面”调用都在“系统事件”应用程序中。

尝试这个。

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
于 2013-09-09T21:23:21.520 回答