Там есть несколько проблем:
- Вы уже нацеливаетесь на процесс Notes, поэтому включение в операторы click добавляет еще одну цель процесса - используйте одну или другую, но если выВы делаете много щелчков по меню, которые вы можете посмотреть, используя универсальный обработчик;
- В пункте меню экспорта используется эллипс (один символ), а не три периода;
- Поместив оператор
display dialog
в оператор сообщения о системных событиях, вы перемещаете фокус в сторону от приложения.
Также обратите внимание, что текстовое поле выбрано, и кнопка сохранения используется по умолчанию. в листе, так что вы можете использовать нажатия клавиш вместо того, чтобы пытаться щелкать элементы пользовательского интерфейса. Пример очистки (проверенный в Мохаве) будет выглядеть примерно так:
tell application "Notes"
launch -- seems to work better than 'activate'
repeat with aFolder in folders
repeat with aNote in notes of aFolder
set noteName to (name of aNote)
try -- keep the name a reasonable length
set noteName to text 1 thru 20 of noteName
end try
tell (current date) to set timeStamp to text 2 thru -1 of (get (1000000 + (its hours) * 10000 + (its minutes) * 100 + (its seconds)) as text) -- hhmmss
tell application "System Events"
#display dialog noteName -- testing?
tell process "Notes"
set frontmost to true -- retarget the Notes app
delay 0.5
click menu item "Export as PDF…" of menu "File" of menu bar item "File" of menu bar 1
repeat until exists sheet 1 of window 1 -- wait for the sheet
delay 0.02
end repeat
end tell
keystroke noteName & "_" & timeStamp -- update the name, trying to avoid duplicates
delay 0.5
keystroke return -- dismiss the sheet
delay 0.5
key code 125
end tell
end repeat
end repeat
end tell