2013-09-09 3 views
1

Я пытаюсь сделать 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 

До сих пор это работает отлично, единственная проблема, с которой я сталкиваюсь, - это когда я подключаю другой монитор, его рабочий стол не изменится. Я попытался решить эту проблему с помощью the following code I found making a web search

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

ответ

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 
+0

Это не работает для меня. У меня только один рабочий стол. Я нахожусь в Mac OS X 10.7. Идеи? – wfaulk

+0

Не уверен, возможно, начнется новый вопрос? – adamh

+0

На самом деле, я думаю, у меня есть решение, если вы хотите начать новый вопрос. – adamh

Смежные вопросы