Создание адресной книги applescript

#text #applescript

#текст #applescript

Вопрос:

Я пытаюсь создать applescript, который откроет документ и добавит все, что я введу в текстовое поле, в документ, а затем сохранит его в пути. Когда я пытаюсь сохранить его, он просто говорит: «не удалось сохранить x, потому что файл не существует».

Вот мой код

 display dialog "username" default answer ""
set the target_username to the text returned of the result
display dialog "password" default answer "" with hidden answer
set the pass to the text returned of the result
if target_username is "Plasma" and pass is "Sship" then
    display dialog "Welcome! Please select a function!" buttons {"Add address", "View address"}
    if button returned of result is "Add address" then
        set booka to text returned of (display dialog "rers!" default answer "")
        tell application "TextEdit"
            activate
            make new document
            set text of document 1 to booka

            delay 10
            set thePath to "/Users/Cameron/Desktop/"
            set thedoc to document 1
            set thetitle to "food"
            save thedoc in (thePath amp; thetitle)
        end tell
    else
        display dialog "no"
    end if
else
    display dialog "no"
end if
}  

Ответ №1:

Приведенный ниже сценарий можно сохранить в текстовом файле.

 set booka to "my string" -- set booka variable just for testing !
tell application "TextEdit"
activate
make new document
set text of document 1 to booka
set thePath to "Users:Cameron:Desktop:food.txt"
tell document 1 to save in file thePath
end tell
  

Комментарии:

1. Скрипт работает для меня, конечно, заменяя ‘Cameron’ на собственное имя пользователя. Вы уверены, что ваш пользователь — «Кэмерон»? (это единственное, что я не могу проверить)

2. Вы случайно не знаете, как открыть тот же документ и написать что-то еще?

3. используйте инструкцию «открыть» в блоке «указать текстовый редактор», задайте новый текст и сохраните снова. Однако, если целью является просто запись текста в текстовый файл, вам не нужно использовать TextEdit. найдите команды «чтение» и «запись» в Applescript.