SECTION 2, APPEND TO SECTION 1
--__________________________________ Sub-routines ________________________________________
-- The actual Printer testing routine
on TestPrinterStatus(PrinterName)
tell application "Printer Setup Utility"
try
set DelayCycle to 1
repeat
delay 0.2
set ThePrinterStatus to status of printer PrinterName as string
if "idle" is in ThePrinterStatus or "constant ****prng" is in ThePrinterStatus then exit repeat
if DelayCycle = 200 then
if ThePrinterStatus = "printing" then
if SpeakTheErrors then say "[[rate " & TheSpeechRate & "]]Waiting for Printer. " & PrinterName & ". to become available. " using TheVoice
set DelayCycle to DelayCycle + 1
end if
end if
if DelayCycle = 1 then
if ThePrinterStatus = "error" then
if SpeakTheErrors then say "[[rate " & TheSpeechRate & "]]There is an error with the printer. " using TheVoice
delay 1
if SpeakTheErrors then say "[[rate " & TheSpeechRate & "]]please check the printer. " & PrinterName using TheVoice
set DelayCycle to DelayCycle + 1
else
if ThePrinterStatus = "stopped" then
if SpeakTheErrors then say "[[rate " & TheSpeechRate & "]]The printing for printer. " & PrinterName & ". is stopped." using TheVoice
delay 1
if SpeakTheErrors then say "[[rate " & TheSpeechRate & "]]please check the printer status with. printer set up utility" using TheVoice
set DelayCycle to DelayCycle + 1
else
if ThePrinterStatus ≠"printing" then
if SpeakTheErrors then say "[[rate " & TheSpeechRate & "]]There is an unknown error with printer. " & PrinterName using TheVoice
delay 1
if SpeakTheErrors then say "[[rate " & TheSpeechRate & "]]The actual error is." & ThePrinterStatus using TheVoice
delay 1
if SpeakTheErrors then say "[[rate " & TheSpeechRate & "]]please check the printer status with. printer set up utility" using TheVoice
delay 0.5
if SpeakTheErrors then say "[[rate " & TheSpeechRate & "]]or. the printer might not be turned on." using TheVoice
if WriteTheErrors then my WriteErrors("Printer Error equals " & ThePrinterStatus & return, "None")
tell application "Printer Setup Utility"
quit
end tell
tell application "Printer Setup Utility"
activate
end tell
set DelayCycle to DelayCycle + 1
end if
end if
end if
end if
set DelayCycle to DelayCycle + 1
if DelayCycle > 200 then set DelayCycle to 1
end repeat
on error TheError number errNum
set DidItPrint to false
set PrintError to "There is a Printer problem with printer " & PrinterName & return & return & TheError & return & return
if WriteTheErrors then my WriteErrors(PrintError, errNum)
if errNum = 1 then
if SpeakTheErrors then say "[[rate " & TheSpeechRate & "]]The printer. " & PrinterName & ". does not exist, or is not available." using TheVoice
end if
end try
end tell
end TestPrinterStatus
on CheckProcessIsOpen(TheApplication)
tell application "Finder"
try
set temp to the name of every process as string
if TheApplication is in temp then
return true
else
set DidItPrint to false
if SpeakTheErrors then say "[[rate " & TheSpeechRate & "]]The Application " & TheApplication & " appears to have quit." using TheVoice
return false
end if
end try
end tell
end CheckProcessIsOpen
on TransferToITMP(CycleThroughMessages, thesound)
tell application "Mail"
try
if not (exists mailbox "* items to manually process") then
make new mailbox with properties {name:"* items to manually process"}
end if
try
set m to name of mailbox of CycleThroughMessages as string
if m ≠"* items to manually process" then
move CycleThroughMessages to mailbox "* items to manually process"
if SpeakTheErrors and thesound then say "[[rate " & TheSpeechRate & "]]The mail file has been transferred to the mail box, items to manually process." using TheVoice
if thesound then set ItMPmailerror to true
end if
on error
--do nuttin'
end try
--get messages of mailbox MailBoxName
end try
end tell
end TransferToITMP
on MoveHoldingFolderToUnrecognizedItems()
tell application "Finder"
try
set bypassMove to true
if ErrorMessage ≠"" then
try
move file RTFPath to folder Unrecognized_Server_Folder -- Copy Onto Server
on error
set ErrorMessage to ErrorMessage & "Emergency" & return & "There is an error saving to the Unrecognizable Items folder to the server." & return & "This is a major error, and should be rectified ASAP." & return
end try
try
if not (exists folder "Unrecognized items for Manual printing") then make new folder with properties {name:"Unrecognized items for Manual printing"}
move folder holding_folder to trash
duplicate file RTFPath to folder "Unrecognized items for Manual printing"
set label index of folder "Unrecognized items for Manual printing" to 1
if SpeakTheErrors then say "[[rate " & TheSpeechRate & "]]The rtf file, with attachments, has been moved to the folder, Unrecognized items for Manual printing. " using TheVoice
set bypassMove to false
on error
set ErrorMessage to ErrorMessage & "Attention!" & return & "There is an error saving to the Unrecognizable Items folder on the desktop." & return & "This is a major error, and should be rectified ASAP." & return
end try
else
if exists folder holding_folder then move folder holding_folder to trash
end if
-- this could add a null string
set ErrorMessage to ErrorMessage & FileSavingErrorMessage
set the_subject to "Alert! Order preparation problem."
set the_content to my SetTheHeading() & ¬
"Errors have been encountered while preparing an email Order for printing." & return & return & ¬
"The errors are..." & return & return & ErrorMessage & return & return & ¬
"The Order email is from " & theSendersFullName & "." & return & return
if ItMPmailerror then set the_content to the_content & "The email has been shifted to the Mail folder 'Items to Manually Process'." & return & return
set thetextflag to false
if not bypassMove then
set the_content to the_content & "The pdf file '" & RTFName & "' has been re-located into the folder 'Unrecognized items for Manual Printing'." & return & return
set thetextflag to true
end if
if CoverPagePrintingmailerror then
set the_content to the_content & "Particularly note that a cover page did not print, and the email has been shifted to the Mailbox 'Items to manually process'." & return
else
set the_content to the_content & "Please note that a cover sheet should have been printed." & return
end if
tell application "Mail"
activate
set newMessage to make new outgoing message with properties {address:the_mailto, subject:the_subject, content:the_content}
tell newMessage
set x to offset of TheBusinessName in the_content
set font of characters x thru (x + (count of TheBusinessName)) of content to "Helvetica Bold"
set color of characters x thru (x + (count of TheBusinessName)) of content to {56342, 2442, 607}
set x to offset of ErrorMessage in the_content
set font of characters x thru (x + (count of ErrorMessage)) of content to "Helvetica Bold"
set color of characters x thru (x + (count of ErrorMessage)) of content to {35288, 1602, 1985}
set x to offset of "'Items to Manually Process'" in the_content
if x > 0 then set font of characters x thru (x + (count of "'Items to Manually Process'")) of content to "Helvetica Bold"
set x to offset of PrintDateTimeName in the_content
if x > 0 then set font of characters x thru (x + (count of PrintDateTimeName)) of content to "Helvetica Bold"
if thetextflag then
set x to offset of "'Unrecognized items for Manual Printing'." in the_content
set font of characters x thru (x + (count of "'Unrecognized items for Manual Printing'.")) of content to "Helvetica Bold"
end if
make new to recipient with properties {address:the_mailto}
send
end tell
end tell
if "Emergency" is in the_content and Emergency_Contact ≠"" and my seeifhourhaselapsed() then
set the_subject to "EMERGENCY! Order preparation problem."
set ErrorMessage to "PLEASE NOTE!"
set the_content to "This is an automated message from the Art Room at " & TheBusinessName & return & return & ErrorMessage & return & return & "There has been a problem occur with the automated printing process." & return & return & "It appears we have a problem with the server, files are not saving. Please investigate it." & return & return & return & "NOTE that this message will be sent only once per hour until the problem is rectified." & return
tell application "Mail"
activate
set newMessage to make new outgoing message with properties {address:Emergency_Contact, subject:the_subject, content:the_content}
tell newMessage
set x to offset of TheBusinessName in the_content
set font of characters x thru (x + (count of TheBusinessName)) of content to "Helvetica Bold"
set color of characters x thru (x + (count of TheBusinessName)) of content to {56342, 2442, 607}
set x to offset of ErrorMessage in the_content
set font of characters x thru (x + (count of ErrorMessage)) of content to "Helvetica Bold"
set color of characters x thru (x + (count of ErrorMessage)) of content to {35288, 1602, 1985}
make new to recipient with properties {address:Emergency_Contact}
send
end tell
end tell
end if
on error TheError number errNum
if errNum ≠-1728 then display dialog errNum & return & "Error in MoveHoldingFolderToUnrecognizedItems" & return & TheError as string
end try
end tell
end MoveHoldingFolderToUnrecognizedItems
on SendABloodyTally(TheTally, theLastMidnight)
set the_subject to "eMail Tally since " & year of theLastMidnight & " " & month of theLastMidnight & " " & day of theLastMidnight
set TallyString to {"Computer processed data since " & theLastMidnight & "..."} & return & return & "Hour " & return
set theLastTally to 0
repeat with x from 1 to 24
set thetemphour to item (3 + (x * 2)) of TheTally as string
set theReadingTally to item (4 + (x * 2)) of TheTally as string
set tempX to x as string
-- This counts the hours, and adds space if below 10
if (count of tempX) < 2 then set tempX to "_" & tempX as string
-- This builds string of asterixes for each hour
set GraphString to ""
repeat with y from 1 to theReadingTally
set GraphString to GraphString & "*"
end repeat
-- This add space if number below 10
if (count of GraphString) < 10 then set theReadingTally to "_" & theReadingTally as string
-- Build Tally string
set end of TallyString to tempX & " : " & theReadingTally & " " & GraphString & return
end repeat
set the_content to (my SetTheHeading() & ¬
"Total Mail items processed : " & item 1 of TheTally as string) & return & return & ¬
"Since " & theLastMidnight & " (Universal time), we computer processed..." & return & return & ¬
"Total Mail for previous period : " & item 2 of TheTally & return & return & ¬
the TallyString & return & return & ¬
"Have a good day."
tell application "Mail"
activate
set newMessage to make new outgoing message with properties {address:the_mailto, subject:the_subject, content:the_content}
tell newMessage
set x to offset of TheBusinessName in the_content
set font of characters x thru (x + (count of TheBusinessName)) of content to "Helvetica Bold"
set color of characters x thru (x + (count of TheBusinessName)) of content to {56342, 2442, 607}
set y to offset of "Hour " in the_content
repeat with x from y to count of the_content
if character x of the_content = "*" then
set color of characters x thru x of content to {56342, 2442, 607}
delay 0.01
set the size of characters x thru x of content to 24
end if
end repeat
make new to recipient with properties {address:the_mailto}
send
end tell
end tell
end SendABloodyTally
on SendMonthlyReport(theMonth, WholeList)
set the_subject to "Processed eMail Tally for " & theMonth & "."
set TallyString to {"Computer processed data for previous " & theMonth & " ..."} & return & return
set theLastTally to 0
set the MonthsTotal to 0
repeat with x from 1 to ((number of items in WholeList) - 2) div 3
set thetempmonth to item (0 + (x * 3)) of WholeList as string
set thetempday to item (1 + (x * 3)) of WholeList as string
set theReadingTally to item (2 + (x * 3)) of WholeList as string
if thetempmonth = theMonth then
set the MonthsTotal to MonthsTotal + theReadingTally
set GraphString to ""
repeat with y from 1 to (theReadingTally + 3) div 4
set GraphString to GraphString & "*"
end repeat
set temp to the theReadingTally as string
if (count of temp) < 2 then set temp to "__" & temp
if (count of temp) < 3 then set temp to "_" & temp
if ((count of thetempday) as string) < 2 then set thetempday to "_" & thetempday as string
set end of TallyString to thetempday & " : " & temp & " " & GraphString & return
end if
end repeat
set the_content to my SetTheHeading() & ¬
"For the previous month (Universal time), we processed..." & return & return & ¬
"Total Mail items processed : " & MonthsTotal & return & return & ¬
the TallyString & return & return & ¬
"Have a good day."
tell application "Mail"
activate
set newMessage to make new outgoing message with properties {address:the_mailto, subject:the_subject, content:the_content}
tell newMessage
set x to offset of TheBusinessName in the_content
set font of characters x thru (x + (count of TheBusinessName)) of content to "Helvetica Bold"
set color of characters x thru (x + (count of TheBusinessName)) of content to {56342, 2442, 607}
make new to recipient with properties {address:the_mailto}
send
end tell
end tell
end SendMonthlyReport
on SetTheHeading()
return ("G'day" & return & return & "This is an automated message from " & TheBusinessName & "." & return & return)
end SetTheHeading
on SetDateTimeName(theEntireSeconds, WorkingDate)
try
set theDays to day of WorkingDate
if theDays < 10 then set theDays to "0" & theDays
set theHours to theEntireSeconds div 3600
set theMinutes to (theEntireSeconds - (theHours * 3600)) div 60
set theSeconds to theEntireSeconds - (theHours * 3600) - (theMinutes * 60)
if theHours < 10 then set theHours to "0" & theHours as string
if theMinutes < 10 then set theMinutes to "0" & theMinutes as string
if theSeconds < 10 then set theSeconds to "0" & theSeconds as string
copy the month of WorkingDate to tempMonth
set StoreMonth to the month of WorkingDate as string
copy ((offset of tempMonth in "jan feb mar apr may jun jul aug sep oct nov dec ") + 3) / 4 as integer to theMonth
if theMonth < 10 then copy "0" & theMonth as string to theMonth
set WorkingDateTimeName to (year of WorkingDate & "-" & theMonth & "-" & theDays as string) & " " & theHours & theMinutes & theSeconds & "Z.rtfd"
return {theMonth, theDays, theHours, theMinutes, theSeconds, WorkingDateTimeName}
end try
end SetDateTimeName
on CheckIfFileExists(temp_Folder, TheFileTempName, TheSuffix)
tell application "Finder"
try
set FileSavingErrorMessage to ""
set The_files to (every item of folder temp_Folder)
set AddOnTime to 0
set The_File_names to {}
repeat with A_File in The_files
set the end of The_File_names to A_File's name
end repeat
if TheFileTempName is in The_File_names then
if TheSuffix ≠"" then set TheFileTempName to my replace_chars(TheFileTempName, "." & TheSuffix, "")
repeat
set AddOnTime to AddOnTime + 1
set xx to characters -5 thru -2 of TheFileTempName as string
set xx to xx + AddOnTime as string
if length of xx = 1 then set xx to "000" & xx as string
if length of xx = 2 then set xx to "00" & xx as string
if length of xx = 3 then set xx to "0" & xx as string
set thetempname to characters 1 thru -6 of TheFileTempName & xx & "Z." & TheSuffix
if thetempname is not in The_File_names then exit repeat
end repeat
set FileSavingErrorMessage to "There was an unusual file saving problem, probably due to the computers clock being reset." & return & "A file with the same name, '" & TheFileTempName & "' already existed." & return & "The file name is now set to '" & thetempname & "'." & return
end if
on error TheError number errNum
display dialog errNum & return & "Error in CheckIfFileExists" & return & TheError as string
end try
end tell
end CheckIfFileExists
on CheckForExistingFileTwo(TheFileTempName, thetempname, append)
try
set RenameIsTrue to false
tell application "Finder"
try
set templist to name of every item of folder holding_folder
if thetempname is in templist or thetempname = templist then
set thetempname to append & " " & TheFileTempName as string
set append to append + 1
set RenameIsTrue to true
my CheckForExistingFileTwo(TheFileTempName, thetempname, append)
else
if exists item TheFileTempName of folder holding_folder then set the name of item TheFileTempName of folder holding_folder to thetempname
end if
on error TheError number errNum
display dialog errNum & return & TheError
end try
end tell
return RenameIsTrue
end try
end CheckForExistingFileTwo
on CheckForExistingFileThree(TheFileTempName, thetempname, TheSuffix, append)
tell application "Finder"
try
if TheSuffix ≠"" then set TheFileTempName to my replace_chars(TheFileTempName, "." & TheSuffix, "")
set templist to name of every item of folder "Unrecognized items for Manual printing"
if (thetempname) is in templist or thetempname = templist then
if TheSuffix ≠"" then
set thetempname to TheFileTempName & " " & append & "." & TheSuffix
else
set thetempname to TheFileTempName & " " & append
end if
set append to append + 1
my CheckForExistingFileThree(TheFileTempName, thetempname, TheSuffix, append)
else
try
if TheSuffix ≠"" then
if exists item (TheFileTempName & "." & TheSuffix) of folder holding_folder then
set the name of item (TheFileTempName & "." & TheSuffix) of folder holding_folder to thetempname
end if
else
if exists item (TheFileTempName) of folder holding_folder then
set the name of item (TheFileTempName) of folder holding_folder to thetempname
end if
end if
end try
return thetempname
end if
on error TheError number errNum
display dialog errNum & return & "CheckForExistingFileThree" & return & TheError as string
end try
end tell
end CheckForExistingFileThree
on seeifhourhaselapsed()
set TheFileName to PathToDesktop & ".DataTimeSave.dat" as string
set now to (current date)
try
set CheckLastTime to ((read file (TheFileName) as «class isot») as date)
set TimeElapsed to now - CheckLastTime
on error
set TimeElapsed to hours + 1
end try
if (TimeElapsed > hours) then
set fRef to (open for access file TheFileName with write permission)
try
set eof fRef to 0
set now to now as «class isot»
write now to fRef
set now to (now as «class isot») as date
end try
close access fRef
return true
else
return false
end if
end seeifhourhaselapsed
on seeiftimehaselapsed(TheTest)
set TheFileName to PathToDesktop & ".DataMinutesSave.dat" as string
set now to (current date)
try
set TestContent to (read file (TheFileName))
if TestContent ≠"" then
set CheckLastTime to ((read file (TheFileName) as «class isot») as date)
set TimeElapsed to now - CheckLastTime
end if
on error
set TimeElapsed to (60 * theMinutesToStop) + 1
end try
if TheTest = "Reset countdown" then
set fRef to (open for access file TheFileName with write permission)
try
set eof fRef to 0
set now to now as «class isot»
write now to fRef
set now to (now as «class isot») as date
close access fRef
end try
return theMinutesToStop - TimeElapsed
else
if (TimeElapsed > 60 * theMinutesToStop) or TheTest = "Reset to empty" then
set fRef to (open for access file TheFileName with write permission)
try
set eof fRef to 0
set temp to ""
write temp to fRef
close access fRef
end try
return ""
else
if TheTest = "Check if elapsed" then
if TestContent = "" then
return ""
else
return (theMinutesToStop * 60) - TimeElapsed
end if
end if
end if
end if
end seeiftimehaselapsed
on SaveTheStartingReference(theItem)
my SaveTheReference(".DataStartName.dat", theItem)
end SaveTheStartingReference
on SaveTheFinishedReference(theItem)
my SaveTheReference(".DataFinishedName.dat", theItem)
end SaveTheFinishedReference
on SaveThePausedReference(theItem)
my SaveTheReference(".DataPausedName.dat", theItem)
end SaveThePausedReference
on SaveTheReference(TheSaveFileList, theItem)
set CheckPrintedList to my ReadFile(TheSaveFileList)
if CheckPrintedList = {} then
set end of CheckPrintedList to 1
end if
set ListLength to item 1 of CheckPrintedList
if theItem is not in CheckPrintedList then
if number of items in CheckPrintedList < 501 then
set end of CheckPrintedList to theItem
set ListLength to ListLength + 1
set item 1 of CheckPrintedList to ListLength
my WriteFile(TheSaveFileList, CheckPrintedList)
else
set ListLength to ListLength + 1
if ListLength > 501 then set ListLength to 2
set item 1 of CheckPrintedList to ListLength
set item ListLength of CheckPrintedList to theItem
my WriteFile(TheSaveFileList, CheckPrintedList)
end if
end if
end SaveTheReference
on CheckTheStartingReference(theItem)
set TheSaveFileList to ".DataStartName.dat"
set CheckPrintedList to my ReadFile(TheSaveFileList)
if theItem is in CheckPrintedList then
return true
else
return false
end if
end CheckTheStartingReference
on CheckTheFinishedReference(theItem)
set TheSaveFileList to ".DataFinishedName.dat"
set CheckPrintedList to my ReadFile(TheSaveFileList)
if theItem is in CheckPrintedList then
return true
else
return false
end if
end CheckTheFinishedReference
on CheckThePausedReference(theItem)
set TheSaveFileList to ".DataPausedName.dat"
set CheckPrintedList to my ReadFile(TheSaveFileList)
if theItem is in CheckPrintedList then
return true
else
return false
end if
end CheckThePausedReference
on SaveAllTheData(TempSubject, FolderDailyName, TheYear)
tell application "Finder"
set The_Data_Desktop_Folder to "Mail Data " & TheYear
if not (exists folder The_Data_Desktop_Folder of desktop) then
make new folder at desktop with properties {name:The_Data_Desktop_Folder}
end if
set TheSaveFileList to The_Data_Desktop_Folder & ":" & FolderDailyName & ".dat"
set CheckPrintedList to PrintDateTimeName & "," & theSendersFullName & "," & TempSubject
my WriteFile3(TheSaveFileList, CheckPrintedList)
end tell
end SaveAllTheData
on SetRunningTally(TheYear, theMonth, theDays)
-- item 1 = Overall running total
-- item 2 = yesterdays total
-- item 3 = todays running total
-- item 4 = the seconds
set TheTally to my ReadFile(".RunningTally")
if TheTally = {} then set TheTally to {0, 0, 0, 0}
set FullTally to item 1 of TheTally
set YesterdaysTally to item 2 of TheTally
set PresentTally to item 3 of TheTally
set theLastSeconds to item 4 of TheTally
try
set theGraphTally to items 5 thru 54 of TheTally
on error
set theGraphTally to {}
repeat 50 times
set end of theGraphTally to 0 as string
end repeat
set TheTally to items 1 thru 4 of TheTally & theGraphTally
end try
set item 1 of TheTally to FullTally + 1
set item 3 of TheTally to PresentTally + 1
set theLastMidnight to my ReadLastMidnight(".SaveLastMidnight")
if theZeroedDate > theLastMidnight then
my WriteLastMidnight(".SaveLastMidnight")
my WriteYearlyData(TheYear, theDays, PresentTally)
set item 2 of the TheTally to PresentTally
set item 3 of TheTally to 1
my SendABloodyTally(TheTally, theLastMidnight)
set theGraphTally to {}
repeat 50 times
set end of theGraphTally to "0" as string
end repeat
set TheTally to items 1 thru 4 of TheTally & theGraphTally
end if
set thehour to theEntireSeconds div 3600 as text
set item ((thehour * 2) + 5) of TheTally to thehour + 1 as string
set item ((thehour * 2) + 6) of TheTally to (item ((thehour * 2) + 6) of TheTally) + 1
set item 4 of TheTally to theEntireSeconds
my WriteFile2(".RunningTally", TheTally)
end SetRunningTally
on ReadLastMidnight(Filename)
tell application "Finder"
set TheFileName to PathToDesktop & Filename as string
try
set theLastMidnight to (read file TheFileName as «class isot») as date
return theLastMidnight
on error
my WriteLastMidnight(Filename)
return theZeroedDate
end try
end tell
end ReadLastMidnight
on WriteLastMidnight(Filename)
set TheFileName to PathToDesktop & Filename as string
set fRef to (open for access file TheFileName with write permission)
set theZeroedDate to theZeroedDate as «class isot»
set eof fRef to 0
try
write theZeroedDate to fRef
end try
close access fRef
set theZeroedDate to (theZeroedDate as «class isot») as date
end WriteLastMidnight
on ReadRunningTally()
set TheTally to my ReadFile(".RunningTally")
if TheTally = {} then set TheTally to {0, 0, 0, 0}
return TheTally
end ReadRunningTally
on WriteYearlyData(TheYear, theDays, DaysTally)
set theYearlyTallyName to ".Yearly Tally " & TheYear as string
set YearlyTallyFile to PathToDesktop & theYearlyTallyName as string
set yearlyTally to my ReadFile(theYearlyTallyName)
if yearlyTally = {} or yearlyTally = "" then
set TheWriteItem to {TheYear, StoreMonth, StoreMonth, theDays, DaysTally}
set fRef to (open for access file YearlyTallyFile with write permission)
set eof fRef to 0
try
repeat with x from 1 to number of items in TheWriteItem
write (item x of TheWriteItem as string) & "," to fRef
end repeat
close access fRef
on error
try
close access fRef
end try
end try
-- Now check for previous years folder, should read December if full
set tempyear to TheYear - 1
set YearlyTallyFile2 to PathToDesktop & ".Yearly Tally " & tempyear as string
try
if exists file YearlyTallyFile2 then
try
set WholeList to (read file YearlyTallyFile2 using delimiter ",")
set thecheckmonth to item 2 of WholeList
my SendMonthlyReport(thecheckmonth, WholeList)
end try
end if
end try
else
try
set fRef to (open for access file YearlyTallyFile with write permission)
write StoreMonth & "," & theDays & "," & DaysTally & "," as string to fRef starting at eof
close access fRef
on error
try
close access fRef
end try
end try
end if
tell application "Finder"
try
set WholeList to (read file (YearlyTallyFile) using delimiter ",")
set thecheckmonth to item 2 of WholeList
if thecheckmonth ≠StoreMonth then
set item 2 of WholeList to StoreMonth
my WriteFile(theYearlyTallyName, WholeList)
my SendMonthlyReport(thecheckmonth, WholeList)
end if
on error
return {}
end try
end tell
end WriteYearlyData
on ReadFile(TheFileName)
set TheFileName to PathToDesktop & TheFileName as string
tell application "Finder"
try
set WholeList to (read file (TheFileName) using delimiter ",")
return WholeList
on error
return {}
end try
end tell
end ReadFile
on WriteFile(TheFileName, TheWriteItem)
set TheFileName to PathToDesktop & TheFileName as string
set fRef to (open for access file TheFileName with write permission)
set eof fRef to 0
try
write (item 1 of TheWriteItem as string) & "," to fRef
repeat with x from 2 to number of items in TheWriteItem
write item x of TheWriteItem & "," to fRef
end repeat
end try
close access fRef
end WriteFile
on WriteFile2(TheFileName, TheWriteItem)
set TheFileName to PathToDesktop & TheFileName as string
set fRef to (open for access file TheFileName with write permission)
set eof fRef to 0
try
repeat with x from 1 to number of items in TheWriteItem
write (item x of TheWriteItem as string) & "," to fRef
end repeat
end try
close access fRef
end WriteFile2
on WriteFile3(TheFileName, TheWriteItem)
set TheFileName to PathToDesktop & TheFileName as string
set fRef to (open for access file TheFileName with write permission)
try
write TheWriteItem & return to fRef starting at eof
end try
close access fRef
end WriteFile3
on WriteErrors(TheWriteItems, errNum)
tell application "Finder"
try
set CheckErrorList to {}
set TheSaveErrorsList to "Item Mover Errors.dat"
set CheckErrorList to my ReadFile(TheSaveErrorsList)
if (count of CheckErrorList) > 50 then set CheckErrorList to items ((count of CheckErrorList) - 49) thru end of CheckErrorList
set end of CheckErrorList to (return & (current date) - (time to GMT) as string) & " Error number : " & errNum & return & TheWriteItems
my WriteFile(TheSaveErrorsList, CheckErrorList)
on error TheError number errNum
-- Do nuttin
end try
end tell
end WriteErrors
on replace_chars(this_text, search_string, replacement_string)
set KeepDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to KeepDelimiters
return this_text
end replace_chars
on getName(TheFileTempName)
set KeepDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
if TheFileTempName > "" then
set TheFileTempName to (text items -1 thru end of TheFileTempName)
end if
set AppleScript's text item delimiters to KeepDelimiters
return TheFileTempName
end getName
on textToList(theText, theSep)
set {myTID, my text item delimiters} to {my text item delimiters, theSep}
set soFar to text items of theText
set my text item delimiters to myTID
return soFar
end textToList
on listToText(thelist, theSep)
set {myTID, my text item delimiters} to {my text item delimiters, theSep}
set soFar to thelist as Unicode text
set my text item delimiters to myTID
return soFar
end listToText
on quit
continue quit
end quit
Model: intel iMac
Browser: Safari 525.18
Operating System: Mac OS X (10.5)