Variable & Read/Write
Variable & Read/Write
- Subject: Variable & Read/Write
- From: "Eichenbaum, Larry" <email@hidden>
- Date: Mon, 19 Mar 2001 14:22:20 -0500
The below application script works well when my source file is less than
about 512K. When the file is larger I receive an error when attempting to
write variable: xPts. I presume I get the error as the source file has not
been read completely and hence the variable is not yet defined. Once this is
sorted out, I imagine I can condense some code to get the actual rewrite of
the source data to run quicker. Some source files can be rather larger
(>10MB).
Thanks,
Larry Eichenbaum
----
The source text files all begin as such:
%!PS-Adobe-1.0
%%BoundingBox: 0 0 594 774
%!PS-AdobeFont-1.0: BowneTimesA-Roman 001.000
Script:
---
on open fileList
parseFiles(fileList)
end open
on parseFiles(fileList)
tell application "Finder"
set workPath to "Macintosh HD:Temp Work:"
repeat with listItems in fileList
try
open for access listItems
read listItems until ":"
set pageParam to (read listItems until "%")
set xPts to (third word of pageParam)
set yPts to (fourth word of pageParam)
close access listItems
on error
beep
end try
set newFile to workPath & "temp.ps"
if (exists file (workPath & "temp.ps")) is true then delete
file (workPath & "temp.ps")
open for access newFile with write permission
set writeData to "<<
/PageSize [" & xPts & " " & yPts & "]
>
> setpagedevice
"
write writeData to newFile
try
open for access listItems
set numEOF to (get eof listItems)
set curEOF to 0
repeat while curEOF < numEOF
set data2 to (read listItems for 10000)
write data2 to newFile
set curEOF to (curEOF + 10000)
end repeat
close access listItems
on error
beep
end try
close access newFile
set creator type of (newFile as alias) to "vgrd"
if (exists file (workPath & (name of listItems))) is true
then
set name of (newFile as alias) to text returned of
(display dialog "File Already Exists... Enter Unique Name." default answer
(name of listItems))
else
set name of (newFile as alias) to fileList
end if
end repeat
end tell
end parseFiles