This is part of a Newton Book Maker suite/project; Book Maker outputs NewtonScript style text files, with “bounds” based on a 240x320 screen. The Newton2100 can handle 1/3-again as much size, so time for bulk math! (I changed numbers by hand to test–it compiles and looks great, but, man!, is it tedious…)
(the “bnd” list is part of a larger file; the list looks like this:)
bnd12 := [0,40,240,52];
bnd13 := [0,52,240,64];
bnd14 := [0,64,240,318];
This droplet will take a text file made from a list as above. It pulls out the “bnd” sets, multiplies each element by 1.325, and saves the results in a new text file alogside the old one
This is a quick hack to save me a lot of typing. I humbly present the code here for any opinions! My version has a couple decent ideas, but it’s sloppy and slow and not very smart (ie., the data has to be in a pretty specific format). Come on! Rip it to shreds…! Seriously, I welcome any tips to streamline my little kludge.
on open theFile
set RevisedBoundsFile to (extract_parent_folder_path_from(theFile)) & "Revised Bounds List.txt"
set BoundsFile to (read theFile) as text
repeat with i in paragraphs of BoundsFile
set BoundsNumber to text ((offset of "d" in i) + 1) thru ((offset of ":" in i) - 2) of i
set BoundsList to stringToList((text ((offset of "[" in i) + 1) thru ((offset of "]" in i) - 1) of i), ",")
set RevisedList to {}
set RevisedList to DoTheMath(BoundsList)
set RevisedBoundsList to "bnd" & BoundsNumber & " := [" & RevisedList & "];" & return
WriteToFile(RevisedBoundsList, RevisedBoundsFile, true)
end repeat
end open
--snip from a macscripter.net post
on stringToList(theString, stringDelimiter)
tell AppleScript
set oldDelimiter to text item delimiters
set text item delimiters to stringDelimiter
set outList to text items of theString
set text item delimiters to oldDelimiter
return outList
end tell
end stringToList
--sloppy snip from a macscripter.net post. could be more elegant; that if/else is nasty..
on DoTheMath(theList)
set TempRevisedList to {}
set listItemsNumber to number of items in theList
repeat with ii from 1 to listItemsNumber
if ii < listItemsNumber then
set TempRevisedList to (TempRevisedList & (round of ((item ii of theList) * 1.325) rounding up) & ",")
else
set TempRevisedList to (TempRevisedList & (round of ((item ii of theList) * 1.325) rounding up))
end if
end repeat
end DoTheMath
--one of Sal Soghoian’s sample sun-routines...
to WriteToFile(this_data, target_file, append_data)
try
set the target_file to the target_file as text
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end WriteToFile
--one of Sal Soghoian’s sample sun-routines...
on extract_parent_folder_path_from(this_filepath)
set this_filepath to this_filepath as text
set x to the offset of ":" in (the reverse of every character of this_filepath) as string
set the parent_folder_path to (characters 1 thru -(x) of this_filepath) as text
return the parent_folder_path
end extract_parent_folder_path_from