при добавлении элементов папки обрабатывать недопустимые операторы AppleScript - PullRequest
0 голосов
/ 21 июня 2019

У меня проблемы с запуском чего-либо, кроме диалогового окна в ручке добавления элементов папки.Код не проходит через операторы if.Любая помощь будет оценена.Код ниже:

on adding folder items to theAttachedFolder after receiving theNewItems
    set author to theNewItems
    if "blah" is in author then
        set theDialogText to "Blah in filename"
        display dialog theDialogText buttons {"Continue", "Close"} default         button "Close" with icon note
        set author to ""
    else if "lol" is in author then
        set theDialogText to "Lol in file name"
        display dialog theDialogText buttons {"Continue", "Close order"} default button "Close" with icon note
        set author to ""
    else if "ha" is in author then
        set theDialogText to "Ha is in file name"
        display dialog theDialogText buttons {"Continue", "Close"} default button "Close" with icon note
        set author to ""
    else if "omg" is in author then
        set theDialogText to "omg is in file name"
        display dialog theDialogText buttons {"Continue", "close"} default button "Close" with icon note
    end if
end adding folder items to

1 Ответ

0 голосов
/ 23 июня 2019

theNewItems - это список из alias спецификаторов.Сравнение этого типа со строкой всегда терпит неудачу.

Вы должны получить имя элемента и вы должны перебрать список файлов

on adding folder items to theAttachedFolder after receiving theNewItems
    repeat with anItem in theNewItems
        tell application "System Events" to set fileName to name of anItem

        if "blah" is in fileName then
            set theDialogText to "Blah in filename"
            display dialog theDialogText buttons {"Continue", "Close"} default button "Close" with icon note
        else if "lol" is in fileName then
            set theDialogText to "Lol in file name"
            display dialog theDialogText buttons {"Continue", "Close order"} default button "Close" with icon note
        else if "ha" is in fileName then
            set theDialogText to "Ha is in file name"
            display dialog theDialogText buttons {"Continue", "Close"} default button "Close" with icon note
        else if "omg" is in fileName then
            set theDialogText to "omg is in file name"
            display dialog theDialogText buttons {"Continue", "close"} default button "Close" with icon note
        end if
    end repeat
end adding folder items to
...