Чекаєте, поки в Applescript з'явиться вікно?


6

Я намагаюся працювати зі сценарієм нижче, і repeat until exists window "Print"цикл ніколи не повертає справжнє (я ніколи не чую звуковий сигнал 3). Це правильний спосіб чекати появи вікна?

Я використовую Інспектор доступності, і це правильна назва діалогового вікна друку.

# Saves current document open in EverNote as PDF
#
activate application "Evernote"
tell application "System Events"
    tell process "EverNote"
        # Open the print dialog
        beep 1
        keystroke "p" using command down

        # Wait until the Print dialog opens before proceeding
        repeat until exists window "Print"
        end repeat

        # Expand the "PDF" menu button (must be expanded before the menu is referencable)
        beep 3

        click menu button "PDF" of window "Print"
        # Wait until the Menu button menu is created before proceeding
        repeat until exists menu item "Save as PDF…" of menu 1 of menu button "PDF" of window "Print"
        end repeat
        # Select the "Save as PDF" menu item
        click menu item "Save as PDF…" of menu 1 of menu button "PDF" of window "Print"

        # Wait until the Save dialog opens before proceeding
        repeat until exists window "Save"
        end repeat

        # Paste the contents of the clipboard in and Save
        # This is sorta hack; Probably best to leave the 'Save As" dialog open and let the user finish it off but I have a special purpose
        if (get (the clipboard) is not "") then
            set value of text field 1 of window "Save" to get (the clipboard) & ".pdf"
        end if
        click button "Save" of window "Save"

    end tell
end tell

Відповіді:


7

Здається, я вирішив основну проблему питання "очікування вікна". Мабуть, вкладені "розповідає" не так добре, тому я вирішив це, вказавши процес, який належить певному елементу інтерфейсу:

repeat until window "Print" of process "Evernote" exists

Не вирішено ввести поточну дату в поле імені файлу на аркуші "Зберегти", але завтра - ще один день! Ось повний сценарій:

activate application "Evernote"
tell application "System Events"

    # Open the print dialog
    keystroke "p" using command down

    # Wait until the Print dialog opens before proceeding
    repeat until window "Print" of process "Evernote" exists
    end repeat

    click menu button "PDF" of window "Print" of process "Evernote"

    # Wait until the Menu button menu is created before proceeding
    repeat until exists menu item "Save as PDF…" of menu 1 of menu button "PDF" of window "Print" of process "Evernote"
    end repeat

    # Select the "Save as PDF" menu item
    click menu item "Save as PDF…" of menu 1 of menu button "PDF" of window "Print" of process "Evernote"

    # Wait until the Save dialog opens before proceeding
    repeat until exists window "Save" of process "Evernote"
    end repeat

    set theDate to current date

    #tell (current date) to get (it's month as integer) & "-" & day & "-" & (it's year as integer)
    #set the clipboard to result as text

    #set myDate to result as text
    #set the clipboard to "dog" as text
    #if (get (the clipboard) is not "") then
    #set value of text field 1 of sheet "Save" of process "Evernote" to get (the clipboard) & ".pdf"
    #end if

    set value of text field of sheet "Save" of process "Evernote" to "dog" & ".pdf"
    # Paste the contents of the clipboard in and Save
    # This is sorta hack; Probably best to leave the 'Save As" dialog open and let the user finish it off but I have a special purpose

    # click button "Save" of window "Save" of process "Evernote"


end tell

Я також користувався tell application "System Events" to tell process "MyProcess" ... blahпевним успіхом.
Олі

Чи повторюється, поки вікно "Друк" процесу "Evernote" існує дійсно для вас? Коли я спробую точно вказати цей рядок, я отримую помилку компіляції, що вказує на "перед Evernote" Очікуваний кінець рядка, але знайдено "" "."
дб

@db - було пару років тому, тому я насправді не пригадую - але я думаю, що так, це спрацювало.
Жодного захоплення
Використовуючи наш веб-сайт, ви визнаєте, що прочитали та зрозуміли наші Політику щодо файлів cookie та Політику конфіденційності.
Licensed under cc by-sa 3.0 with attribution required.