如何在applescript中获取桌面列表

如何在applescript中获取桌面列表,applescript,wallpaper,multiple-monitors,Applescript,Wallpaper,Multiple Monitors,我正在尝试制作一个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

我正在尝试制作一个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
到目前为止,它工作正常,唯一的问题是当我连接另一个显示器时,他的桌面图片不会改变。 我试着用计算机解决这个问题

但这段代码不会编译,因为我得到一个语法错误,它说:

需要类名,但找到属性。

在第4行突出显示桌面的情况下,您在找到的代码中省略了告诉应用程序“系统事件”块

在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

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

在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

这对我不管用。我只有一个桌面。我使用的是MacOSX10.7。想法?不确定,也许开始一个新问题?事实上,如果你想开始一个新问题,我想我有一个解决方案。这对我不起作用。我只有一个桌面。我使用的是MacOSX10.7。想法?不确定,也许开始一个新问题?事实上,如果你想开始一个新问题,我想我有一个解决方案。