如何在applescript中获取桌面列表

维蒂克

我正在尝试制作一个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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在applescript中创建记录列表

来自分类Dev

如何在Applescript中的Word 2011中获取选定的文本

来自分类Dev

如何在Applescript中按名称获取Word文档窗口?

来自分类Dev

Applescript - 如何在 Microsoft Word 中获取单词的文本范围

来自分类Dev

如何在applescript中获取用户语音输入

来自分类Dev

如何在python中获取桌面项目计数?

来自分类Dev

如何在python中获取文件列表的列表列表?

来自分类Dev

如何在 Camunda 中获取任务列表?

来自分类Dev

如何在列表中获取 GameObject 索引?

来自分类Dev

如何在AppleScript中返回列表项的名称并使列表与另一个匹配?

来自分类Dev

如何在haskell的列表中获取最短列表

来自分类Dev

如何在Apex Salesforce中获取列表的子列表?

来自分类Dev

如何在haskell的列表中获取最短列表

来自分类Dev

如何在AppleScript中使用javascript返回聊天室中的用户列表

来自分类Dev

如何在applescript中获取Mac消息应用程序的消息计数*不发送邮件*

来自分类Dev

如何在applescript中获取Mac消息应用程序的消息计数*不发送邮件*

来自分类Dev

如何在桌面.NET应用程序中获取BLE广告回调?

来自分类Dev

如何在桌面应用程序中获取当前地理位置?

来自分类Dev

如何在red hat Linux shell脚本中获取指定用户的桌面文件夹

来自分类Dev

如何在AppleScript中操作“数据”对象

来自分类Dev

如何在AppleScript中操作“数据”对象

来自分类Dev

如何使用AppleScript获取已安装语音的列表?

来自分类Dev

如何使用AppleScript获取已安装语音的列表?

来自分类Dev

如何在jQuery中获取下拉列表选项的数量

来自分类Dev

如何在组合框下拉列表中获取每个值?

来自分类Dev

如何在freemarker模板中按索引获取列表项?

来自分类常见问题

如何在gulp中获取可用任务列表

来自分类Dev

如何在Rails中获取更新属性的列表?

来自分类Dev

如何在linq groupby中获取分组值的列表?

Related 相关文章

  1. 1

    如何在applescript中创建记录列表

  2. 2

    如何在Applescript中的Word 2011中获取选定的文本

  3. 3

    如何在Applescript中按名称获取Word文档窗口?

  4. 4

    Applescript - 如何在 Microsoft Word 中获取单词的文本范围

  5. 5

    如何在applescript中获取用户语音输入

  6. 6

    如何在python中获取桌面项目计数?

  7. 7

    如何在python中获取文件列表的列表列表?

  8. 8

    如何在 Camunda 中获取任务列表?

  9. 9

    如何在列表中获取 GameObject 索引?

  10. 10

    如何在AppleScript中返回列表项的名称并使列表与另一个匹配?

  11. 11

    如何在haskell的列表中获取最短列表

  12. 12

    如何在Apex Salesforce中获取列表的子列表?

  13. 13

    如何在haskell的列表中获取最短列表

  14. 14

    如何在AppleScript中使用javascript返回聊天室中的用户列表

  15. 15

    如何在applescript中获取Mac消息应用程序的消息计数*不发送邮件*

  16. 16

    如何在applescript中获取Mac消息应用程序的消息计数*不发送邮件*

  17. 17

    如何在桌面.NET应用程序中获取BLE广告回调?

  18. 18

    如何在桌面应用程序中获取当前地理位置?

  19. 19

    如何在red hat Linux shell脚本中获取指定用户的桌面文件夹

  20. 20

    如何在AppleScript中操作“数据”对象

  21. 21

    如何在AppleScript中操作“数据”对象

  22. 22

    如何使用AppleScript获取已安装语音的列表?

  23. 23

    如何使用AppleScript获取已安装语音的列表?

  24. 24

    如何在jQuery中获取下拉列表选项的数量

  25. 25

    如何在组合框下拉列表中获取每个值?

  26. 26

    如何在freemarker模板中按索引获取列表项?

  27. 27

    如何在gulp中获取可用任务列表

  28. 28

    如何在Rails中获取更新属性的列表?

  29. 29

    如何在linq groupby中获取分组值的列表?

热门标签

归档