Hi. So I’m new to applescript , and i’m trying to do script that opens text edit, you can choose if you want to write today date or today time, and after that it has to change text size. But i get Syntax error. Could you help me?
Script:
tell application “TextEdit” to open
set question to display dialog “Ką norite sužinoti?” buttons {“Datą”, “Laiką”} default button 2
set answer to button returned of question
if answer is equal to “Datą” then
set the the text of the front document to current date default button 2
end if
if answer is equal to “No” then
set the the text of the front document to current time default button 2
end if
set the size of the text of the front document to “150”
end tell
Errors are so numerous that I can’t list them.
Here is a version - far from optimized - doing the job.
# CAUTION, a TextEdit document MUST be open
tell application "TextEdit"
open
--make new document
set question to display dialog "Ką norite sužinoti?" buttons {"Datą", "Laiką"} default button 2
set answer to button returned of question
if answer is equal to "Datą" then
tell me to set currentDate to (current date) as text
set the the text of the front document to currentDate --default button 2
end if
if answer is equal to "Laiką" then # You tested upon "No" but there is no such button
tell me to set currentTime to time string of (current date)
set the the text of the front document to currentTime --default button 2
end if
set the size of the text of the front document to 150
end tell
Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) jeudi 12 octobre 2017 21:11:59
Thanks for the feedback.
Here is a refined version.
set question to display dialog "Ką norite sužinoti?" buttons {"Datą", "Laiką"} default button 2
if button returned of question is "Datą" then
-- set theText to (current date) as text
set theText to date string of (current date) # Maybe it's what you really need
else
set theText to time string of (current date)
end if
tell application "TextEdit"
activate
# If there is no window available, create a new document
if (count windows) = 0 then make new document
tell document 1
set its text to theText
set size of its text to 150
end tell
set bounds of window 1 to {0, 23, 930, 520}
end tell
Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) samedi 14 octobre 2017 19:23:50