Hi Mytzlscript,
and thank you for your suggestions! However, I still can’t get it to work on my side:
When I run your code
tell application “Finder”
set inFileName to “Mac HD:Desktop Folder:DSLKosten”
set intLineCount to read inFile as text using delimiter return
end tell
I first get an error message, saying that the ‘text is too long to be displayed,
only the first 20000 characters will be displayed’. The display then looks like
{"¨«(p«(H?ÄÔH
(«(ÄPØÏ(dÅ
d+Eë(˫(?
?į0«(??ĉѫ(¿PØÏ?á·L·…}
When I run the script against a BBEdit file I get an “End of file error”.
I can’t find any useful helpfiles for file handling via AppleScript, so I would
be really greatful if we could work it out via this forum. What I am trying to do
is to process my online bill. I download the bill and save it as a text file.
One line displays the download amount, the next line the corresponding online time.
For now I only need the online time, that is every other line. I wrote the following
code to process the file but since the loop stops at line 135 I don’t get the
right result. As far as I can see, all lines (including line 135, the line before and
the line after) have the same return delimiter. Here is the whole program:
tell application “Finder” --creating the output file
if exists (file “MacOS9:desktop folder:DSLKosten2”) then
deleteFile “MacOS9:desktop folder:DSLKosten2”
delay 2 --seconds
end if
end tell
tell application “Finder” to make file at desktop with properties {name:¬
“DSLKosten2”, creator type:“R*ch”, file type:“TEXT”}
set inFileName to “DSLKosten”
set inFile to alias ((path to desktop as string) & inFileName)
set outFile to alias ((path to desktop as string) & “DSLKosten2”)
set sumTime to 0
tell application “AppleWorks 6”
set totLines to number of paragraphs in text body of document inFileName
set fref to (open for access outFile with write permission)
repeat with i from 2 to totLines by 2
set myRec to paragraph i in text body of document inFileName as string
set myDay to (characters 1 thru 10 of myRec as string)
set onlineTime to (word 1 of (characters 20 thru 34 of myRec as string) as integer)
set sumTime to (sumTime + onlineTime)
set outRec to myDay & " " & onlineTime & "
"
write outRec to outFile
end repeat
close access fref
end tell
set myHours to sumTime div 60
set myMinutes to sumTime mod 60
display dialog "Time online: " & sumTime & “Minutes " & return & myHours & ¬
" hours and " & myMinutes & " minutes”
Thanks in advance for any help!