Как получить список рабочих столов в 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


person Witik    schedule 09.09.2013    source источник


Ответы (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
person adamh    schedule 09.09.2013
comment
Это не работает для меня. У меня только один рабочий стол. Я на Mac OS X 10.7. Идеи? - person wfaulk; 12.12.2013
comment
Не уверен, может быть, начать новый вопрос об этом? - person adamh; 13.12.2013
comment
На самом деле, я думаю, у меня есть решение, если вы хотите начать новый вопрос. - person adamh; 13.12.2013