Need help with an old script to join text files
Need help with an old script to join text files
- Subject: Need help with an old script to join text files
- From: Wade Riddick <email@hidden>
- Date: Fri, 10 May 2002 10:19:40 -0500
A long, long, long, long time ago in a city far, far, far away I wrote a
number of scripts to split up and join email digests. This is the prequel
script to that project (the second in fact).
As I recover from a long illness, I'm attempting to get back into
programming. I've been trying to update this script, but have been
stumped. It works fine in System 8, but not in 9 or X. These "modern"
operating systems choke on the "sort" command, however that's not what's
really bugging them. I've taken the sort out and managed to bring down the
OS X kernel.
I'm running 10.1.4 and Applescript 1.8.whatever.
Any ideas what could bring down the Roman Numeral Operating System?
- Spartacus
- No, I'm Spartacus.
- I'm Spartacus.
on run
display dialog "Please drop files to merge on the app."
end run
-- Since 8.5 used to crap out at more than 4K characters, I grab text in 2K
chunks
on GrabChar(sourceStr, i, j)
local i,j,l,jj,tempstr,x
set l to length of sourceStr
if j=-1 then set j to l
if i > j or i > l then return ""
if (j > l) then
set jj to l
else
set jj to j
end if
if (jj-i) > 2000 then
set Tempstr to GrabChar(sourceStr,i,i+2000)
repeat with j from i+2001 to jj by 2000
set x to j+1999
if x>jj then set x to jj
set tempStr to tempstr & GrabChar(sourceStr,j,x)
end repeat
return (tempStr as string)
else if i=jj then
return (item i of sourceStr) as string
else
return (get text of characters i thru jj of sourceStr) as string
end if
end GrabChar
on FileExists(what)
set DoesExist to true
try
set attr to GetFileAttributes alias (what)
on error
set DoesExist to false
end try
return DoesExist
end FileExists
on open DropList
set NumFiles to length of DropList
set tip to (item 1 of droplist) as string
if Numfiles=1 then
display dialog "Don't be a dummy. Needs 2+ files."
return
end if
set tlist to {}
repeat with objectRef in DropList
set tlist to tlist & (objectref as string)
end repeat
set weldList to sort tlist in ascending order case sensitivity true
set i to last item of (offsets of ":" in tip)
set mastername to GrabChar(tip, 1, i) & ""
-- make the new file
if FileExists(Mastername) then
display dialog "A file named '" & Mastername & "' already exists."
buttons {"OK"}
return
end if
open for access file (mastername) with write permission
set eof of file (mastername) to 0
write "" to file (mastername) starting at 0
close access file (mastername)
set attr to GetFileAttributes alias (mastername)
set creatorid of attr to "MSWD"
set typeid of attr to "TEXT"
SetFileAttributes alias (mastername) to attr
repeat with whichFile in weldlist
set l to 200000
set i to 1
open for access alias whichFile
set fl to get eof file whichFile
repeat while i<fl
set howmuch to i+l-1
if howmuch>fl then set howmuch to fl
set FileString to read alias whichFile from i to howmuch
set i to i+l
set refn to (open for access file (mastername) with write permission)
positionFile refn at (getFileLength refn)
write FileString to File (mastername)
close access file (mastername)
end repeat
close access file whichFile
end repeat
Kill Resource Fork file (mastername)
end open
-- If you know how to do all this in three lines of PERL... it would make
my head hurt.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.