Sunday, October 22, 2017

#1 2017-10-12 01:35:14 pm

tomaslt11
Member
Registered: 2017-10-12
Posts: 2

Why is this script not working?

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

Offline

 

#2 2017-10-12 02:12:12 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3200

Re: Why is this script not working?

Errors are so numerous that I can't list them.
Here is a version - far from optimized - doing the job.

Applescript:

# 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

Offline

 

#3 2017-10-12 03:49:10 pm

tomaslt11
Member
Registered: 2017-10-12
Posts: 2

Re: Why is this script not working?

Thanks!

Offline

 

#4 2017-10-14 12:23:56 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3200

Re: Why is this script not working?

Thanks for the feedback.

Here is a refined version.

Applescript:

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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)