regarding the book it should be possible to calculate integer…
set received_data to read received_file as string
set received_data to received_data as integer
set sent_data to read sent_file as string
set sent_data to sent_data as integer
set gesamt to received_data + sent_data
to get the input of the file I set first the variables:
set sent_file to ((path to me as string) & "Contents:Resources:sent.txt") as file specification
set received_file to ((path to me as string) & "Contents:Resources:received.txt") as file specification
To Read I use this commands:
set received_data to read received_file as string
set received_data to received_datat as number
display dialog received_data
set sent_data to read sent_file as string
set sent_data to sent_data as number
display dialog sent_data
The Output is received_data: 20, sent_data: 320
When I try to summ it I get an error that is not able to make “20” into type number…
you have to be very strong now - I found the solution:
It´s not the same wheter you write a number by hand in a file or by applescript! Entering
a number by hand into a file will result with an error - writing to a file with your script
will do exactly what you want…
That means, I first write (for testing purposes) a number into a file with applescript and
now the summ function is working as expected…
That depends on what application you’re writing (by hand) with. Rich Text Format, for example won’t work. The document has to be text. If you write it from AppleScript and retreive it from AppleScript it’ll work because the formats and text encoding of the two are the same, but if you write it in one encoding and try to read it in another, no go.
since I am writing the variable as string everthing is working fine - so if someone needs the code I will put it in here:
Setting the File (File is inside the Application (in Resources)
set sent_file to ((path to me as Unicode text) & "Contents:Resources:sent.txt") as file specification
set received_file to ((path to me as Unicode text) & "Contents:Resources:received.txt") as file specification
Writing to File:
set file_sent to open for access sent_file with write permission
set eof of sent_file to 0
write (sent_final as string) to sent_file starting at eof
close access sent_file
Reading from file
set received_data to read received_file as string
set sent_data to read sent_file as string
expect the unexpected! In my application I try to write to file when the application is quitting or when the red button is pressed! The only thing which will be written (alltough I use the same code as before) is “true” to the file…
on will close theObject
if name of the theObject is "main" then
if modem_display is "Web'n'walk Box compact" then
do shell script quoted form of POSIX path of ((path to me as Unicode text) & "Contents:Resources:Web'n'walk Manager") & " disconnect 0"
else if modem_display is "Web'n'walk Box" then
do shell script quoted form of POSIX path of ((path to me as Unicode text) & "Contents:Resources:Web'n'walk Manager") & " disconnect 1"
else if modem_display is "Web'n'walk Card express" then
do shell script quoted form of POSIX path of ((path to me as Unicode text) & "Contents:Resources:Web'n'walk Manager") & " disconnect 2"
end if
-- Hier werden die gesendeten/empfangen Daten geschrieben
if received_final does not contain "true" then
set file_received to open for access received_file with write permission
set eof of received_file to 0
write (received_final as string) to received_file starting at eof
close access received_file
end if
if sent_final does not contain "true" then
set file_sent to open for access sent_file with write permission
set eof of sent_file to 0
write (sent_final as string) to sent_file starting at eof
close access sent_file
end if
end if
quit
delay 1
end will close