如何获得的AppleScript的桌面列表 [英] How to get a list of the desktops in applescript

查看:262
本文介绍了如何获得的AppleScript的桌面列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使,它可以让我改变桌面图片随机图片的文件夹在我的硬盘驱动器上的AppleScript

I'm trying to make an applescript that let's me change the desktop picture to a random picture in a folder on my hard drive

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

到目前为止,它完美的作品,我唯一的问题是,当我连接另一台显示器,他的桌面图片不会改变。
我试图解决这个问题,<一个href=\"http://www.scibuff.com/2009/11/10/applescript-change-the-desktop-picture-wallpaper-of-two-or-more-screens/\"相对=nofollow称号=设置theDesktops向每个桌面参考>以下code,我发现做一个网络搜索

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

但是,当我得到一个语法错误,说这句话的code将不能编译:

But this code won't compile as I get a syntax error saying:

预期的类名,但发现属性。
随着桌面突出显示4行

推荐答案

您省略了告诉应用程序系统事件块从code你找到了。

You have omitted the tell application "System Events" block from the code you found.

在AppleScript的一些命令中的具体应用字典存在,必须以告诉应用程序块引用。在这种情况下,每个桌面通话中系统事件的应用程序。

In Applescript some commands exist in the dictionary of specific applications and must be referenced with a 'tell application' block. In this case the 'every desktop' call is in the "System Events" app.

试试这个。

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的桌面列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆