Stack Overflow running script from BBEdit

I am having some serious trouble with a script and was hoping someone could help me.

Every time I try to run this, I get a stack overflow error. I have allocated 10000K to both the application, and the Script editor, but no Joy.

The line that is causing the error is in Bold

tell application “Finder”
activate
set MobiFolder to “QUARK:_OEB.Project:FileProcessing:Mobi”
set OEBFolder to choose folder with prompt “Select the folder your OEB is in”
set OEBList to the name of items of alias OEBFolder
set QTY to number of items of OEBList
set a to 0
select alias OEBFolder
copy selection to folder “FileProcessing” of folder “_OEB.Project” of disk “QUARK”
select folder “OEB” of folder “FileProcessing” of folder “_OEB.Project” of disk “QUARK”
set name of selection to “Mobi”
tell application “BBEdit 6.5”
activate
select (file whose name contains “.css”) of alias MobiFolder
open selection
set the_CSS to text 1 of text window 1
return the_CSS
repeat QTY times
set a to a + 1
set the_file to item a of OEBList
select the_file
open selection
replace " <link type="text/css" href="(["]*)" />" using "
" & the_CSS & "

" searching in text 1 of text window 1 options {search mode:grep, starting at top:true, wrap around:false, reverse:false, case sensitive:false, match words:false, extend selection:false}
save window 1
close window 1
end repeat
end tell
end tell

It isn’t nessesary to work with the “selection,” just move or copy files directly by name.

copy (alias OEBFolder) to ...

First: only the Finder works with “file selections.” You just want to tell BBEdit to open a particular file.

tell application "BBEdit 6.5"
	open (alias yourPathString)

Second: you’re trying to use a filter reference (‘whose’ clause) to locate a particular file. This needs to be done in Finder, and not in BBEdit:

tell application "Finder"
	set myAlias to (first file of (alias MobiFolder) whose name ends with ".css") as alias
end tell
tell application "BBEdit 6.5"
	open myAlias