Each time I run the following script, I get the following error; “Exit statement was not in a repeat loop.” when it calls the first handler. prior to this, I was getting the script to run through, but the event log simply showed addTheText() over and over and over - but it never actually executed.
Can anyone figure out why?
set folderLocation to (choose folder with prompt "Where is the folder you would like to work on?") as string
set allFolders to list folder folderLocation without invisibles
set folderCount to the number of items in allFolders
set n to 9
set pageNum to 1
set imageFolder to ""
set htmlTemplate to "TXT document with basic html format" as string
set inventoryDocument to (imageFolder & " inventory" & pageNum & ".html") as string
set anItem to ""
set anItem2 to ""
set anItem3 to ""
set anItem4 to ""
set anItem5 to ""
set x to ""
set n to ""
global pageNum, inventoryDocument, anItem, anItem2, anItem3, anItem4, anItem5, htmlTemplate, x, n
repeat with y from 1 to folderCount
set imageFolderName to item y of allFolders
set imageFolder to (folderLocation & imageFolderName) as string
set allFiles to list folder imageFolder without invisibles
set allFilesCount to the number of items in allFiles
tell application "TextWrangler"
open file htmlTemplate
end tell
repeat with x from 1 to allFilesCount by 5
tell application "TextWrangler"
if x = "" then
exit repeat
else
tell me to addTheText()
if (x + 4 = 100) then saveTheDocument()
end if
end tell
end repeat
tell application "TextWrangler"
tell front document
save front document to file inventoryDocument
close front document
set pageNum to 1
set n to 9
end tell
end tell
end repeat
on addTheText()
tell application "TextWrangler"
tell front document
try
set anItem to (item x of allFiles)
on error
exit repeat
end try
try
set anItem2 to (item (x + 1) of allFiles)
on error
exit repeat
end try
try
set anItem3 to (item (x + 2) of allFiles)
on error
exit repeat
end try
try
set anItem4 to (item (x + 3) of allFiles)
on error
exit repeat
end try
try
set anItem5 to (item (x + 4) of allFiles)
on error
exit repeat
end try
tell line n
set contents to ("<a href=" & anItem & "><img src=" & anItem & " width=" & (ASCII character 34) & "170" & (ASCII character 34) & "></a> <a href=" & anItem2 & "><img src=" & anItem2 & " width=" & (ASCII character 34) & "170" & (ASCII character 34) & "></a> <a href=" & anItem3 & "><img src=" & anItem3 & " width=" & (ASCII character 34) & "170" & (ASCII character 34) & "></a> <a href=" & anItem4 & "> <img src=" & anItem4 & " width=" & (ASCII character 34) & "170" & (ASCII character 34) & "></a> <a href=" & anItem5 & "><img src=" & anItem5 & " width=" & (ASCII character 34) & "170" & (ASCII character 34) & "></a> <br>" & return) as string
end tell
set n to (n + 1)
end tell
end tell
end addTheText
to saveTheDocument()
tell application "TextWrangler"
tell front document
tell line n to set conents to ("<br><br><a href=" & imageFolder & " inventory" & (pageNum + 1) & ".html>Next Page</a>") as string
save front document to file inventoryDocument
close front document
set pageNum to (pageNum + 1)
end tell
end tell
end saveTheDocument