Forums | MacLife

You are not logged in.

#1 2008-03-25 7:30 pm

the macman
Member
Registered: 2008-01-13
Posts: 21

applescript text thing

Ok so I made this cool claculator script that uses only error message windows uning the "display dialog" code. It works really well, but I want it to save the results into a text file. So far I have this:

Code:

tell application "TextEdit"
    activate
    make new document
    set text of document 1 to NumberOne & " " & AdditionOrSubtraction & " " & NumberTwo & " " & " =  " & AnswerOne & " " & AdditionOrSub & " " & AnswerTwo & " " & " =  " & AnswerThree as text
    save document 1 as "supercalcresults.txt"
end tell

This works okay but it wont save, it just makes a new window. I also want it to save the results of EVERY time you use it. Preferably using a date stamp using the :

Code:

set TheDate to current date
set TheTime to the time string of TheDate

code and just using the variable TheTime to place the date and time at the top of the equation.
Ex:

Code:

Mar5 4:00
2 add 4 = 6 add 2 = 8

if the complete code helps you understand the variables I will Post it.

Thanks for your help!!!!!!!


"These go up to eleven"
-Nigel Brian Emerson Tufnel
Spinal Tap

Offline

 

#2 2008-04-23 10:27 pm

matt
Screw it
Registered: 1999-09-16
Posts: 16473
Website

Re: applescript text thing

Sorry it took so long. I rarely come in this forum.

This should work:

Code:

set TheDate to current date
set TheTime to the time string of TheDate

set fileText to NumberOne & " " & AdditionOrSubtraction & " " & NumberTwo & " " & " =  " & AnswerOne & " " & AdditionOrSub & " " & AnswerTwo & " " & " =  " & AnswerThree as text

set thisFile to (path to desktop as string) & "supercalcresults.txt" as string
set theOpenFile to open for access thisFile with write permission

write theTime to theOpenFile
write fileText to theOpenFile
close access theOpenFile

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson