
Indexer for Personal Web Sharing
This is a script for creating html index files for any root folder. The script can be compiled into an applet that creates a file called "index.html" in each subfolder of the root folder that is dragged onto it. These index.html files contain active links for the items in the corresponding folder. In the root folder is also created a file called fullindex.html which contains active links for every file listed in all the individual index.html files.
Because Personal web sharing serves the index.html file for a directory by default, this script can be used to insure that only the desired files will appear in the browser window for that directory. This is accomplished by using Finder labels. By default, this script will create listings only for files that have no Finder label.
Initially, you should use the script by dragging your selected web sharing folder onto the script applet. When you drag your folder to the applet you'll be prompted to enter your ip address or domain name so that the active links can be properly . The applet does the rest.
Caution: Don't run the script if any you already have index.html files of your own that you want to keep in the target directories, because they will be ruined by the script.
You can compile the scripts by copying them from this page, pasting them into a Script Editor document and saving the document as an application with the Never Show Startup Screen option selected. If you have trouble compiling the script after installing the Scripting Additions listed below, be sure that no single script lines have wrapped in the editor except where this symbol "¬" appears at the end of the line.
You may download compiled versions of the script here. The download package includes these instructions as well as an undo indexing applet that will delete all the files created by either of the indexer applets. Be careful with this because it will delete index.html files from any subfolder of folders dragged onto it.
All three scripts require two non-standard scripting additions:
Jon's commands 2.1 available from http://www.seanet.com/~jonpugh/
and
Akua Sweets 1.3.8 available from http://www.akua.com.
What You Need to Know about theTwo Versions
Two versions of the script are included on this page. Version 1 can be compiled into an applet that performs the indexing action on a folder dragged onto it and Version 2 can be compiled into an applet that indexes a specified folder when launched.
Version 2 is easier to use to update the index routinely. Of course the file path and ip address or domain name must be supplied for the Version 2 script before it is compiled. The necessary path information must be provided at the location indicated by red text in the script text. Important: Replace only the text displayed in red in the script snippets on this page, case does matter, and don't add quotes.
The criteria for listing files (based on Finder labels as mentioned above) can also be changed. The line in the script text that affects this parameter is indicated by green text in both versions of the script.
The Scripts
Version 1 - for dragging
-- Properties
property kasHtHead : {"<HTML>", "<HEAD>", "<TITLE>", "Index", ¬
"</TITLE>", "</HEAD>", "<BODY BGCOLOR=\"#FFFFFF\">", ¬
"<H1>", "Index Results", "</H1>"}
property kasHtTail : {"</BODY>", "</HTML>"}
property kasTblHead : {"<TABLE BORDER=0 ¬
CELLPADDING=0 CELLSPACING=2>"}
property kasRowHead : {"<TR>", "<TD VALIGN=top>"}
property kasRowDiv1 : {"</TD>"}
property kasRowTail : {"</TR>"}
property kasTblTail : {"</TABLE>"}
property linklead : {"http://"}
property serverhead : {}
property frontlink : {"<A HREF="}
property endlink : {"</A>"}
property kasName : {"Index"}
property fsObjs : {}
-- Globals
global gasFoldersToDo -- The folders left to process
global startblock
on open (fsObjs)
display dialog "Enter host domain name or IP address as
displayed in the Web Sharing Control Panel.
Example: \"www.apple.com\" or \"127.122.23.111\"" default answer ""
set serverhead to (the text returned of the result) & "/"
set total to (number of (the entries in fsObjs to a depth of -1)) / 3
set pw to display progress ¬
"Making Index Files" subtitled "Progress..." maximum total
tell application "Finder"
if exists file ((fsObjs as string) & "fullindex.html") then
deleteFile ((fsObjs as string) & "fullindex.html")
a new file in fsObjs named "fullindex.html"
else
a new file in fsObjs named "fullindex.html"
end if
end tell
set startblock to fsObjs
-- Do files
set gasFoldersToDo to {}
repeat with fsObj in fsObjs
set myInfo to (basic info for fsObj)
if (file type of myInfo is "fold") then
set gasFoldersToDo to gasFoldersToDo & {fsObj}
end if
end repeat
-- Do folders
repeat while gasFoldersToDo is not {}
-- Pop one off the end
set n to the number of items of gasFoldersToDo
set fsObj to item n of gasFoldersToDo
if (n > 1) then
set gasFoldersToDo to items 1 ¬
through (n - 1) of gasFoldersToDo
else
set gasFoldersToDo to {}
end if
-- Process it
DoOne(fsObj)
GoDeep(fsObj)
end repeat
fixindex()
display progress "Making Index Files" subtitled "Progress..." with disposal
end open
on DoOne(fsObj)
makefileitem(fsObj)
end DoOne
on GoDeep(foldObj)
set daddy to foldObj as string
-- Do folders
set myItems to the entries in foldObj ¬
whose kinds are a folder
repeat with myItem in myItems
set gasFoldersToDo to gasFoldersToDo & ¬
{(daddy & myItem) as alias}
end repeat
end GoDeep
on makefileitem(fsObj)
display progress "Making Index Files" subtitled "Progress..." value 0
tell application "Finder"
try
set theFiles to (the entries in fsObj as alias ¬
whose kinds are a file whose labels are in 0)
end try
set target_file_path to (fsObj) & "index.html"
set |html| to kasHtHead & kasTblHead
repeat with theFile in theFiles
if theFile's name is not in {"index.html", "fullindex.html"} then
set ciName to munge the theFile ¬
as string from startblock as string to ""
set toplink to linklead & serverhead & ¬
{munge ciName from ":" to "/"} as text
set toplink to munge ¬
toplink as string from " " to "%20"
set mainlink to frontlink & toplink & ">" as text
set justName to mainlink & ¬
(munge (theFile as string) from ¬
(fsObj as string) to "") & endlink as text
set |html| to |html| & kasRowHead & ¬
justName & kasRowDiv1
end if
end repeat
set listhtml to |html| & kasRowTail & kasTblTail & kasHtTail
set htTxt to compile ML listhtml
set the target_file_path to the target_file_path as text
set the open_target_file to open for access ¬
the file target_file_path with write permission
set eof of the open_target_file to 0
write htTxt to the open_target_file starting at eof
close access the open_target_file
set theFolders to (the entries in fsObj ¬
as alias whose kinds are a folder)
repeat with thefolder in theFolders
set ciName to munge ¬
the thefolder as string from startblock as string to ""
set toplink to linklead & serverhead & ¬
{munge ciName from ":" to "/"} as text
set toplink to munge toplink as string from " " to "%20"
set mainlink to frontlink & toplink & ">" as text
set nocolfol to munge (thefolder as string) from ":" to ""
set nocolobj to munge (fsObj as string) from ":" to ""
set justName to mainlink & (munge nocolfol from nocolobj to "") ¬
& "/" & endlink as text
set |html| to |html| & kasRowHead & justName & kasRowDiv1
end repeat
set listhtml to |html| & kasRowTail & kasTblTail & kasHtTail
set htTxt to compile ML listhtml
set the target_file_path to the target_file_path as text
set the open_target_file to open for access ¬
the file target_file_path with write permission
set eof of the open_target_file to 0
write htTxt to the open_target_file starting at eof
close access the open_target_file
set midhtml to listhtml
set midhtml to munge ¬
midhtml as string from kasHtHead as text to ""
set midhtml to munge ¬
midhtml as string from kasTblHead as text to ""
set midhtml to munge ¬
midhtml as string from kasTblTail as text to ""
set midhtml to munge ¬
midhtml as string from kasHtTail as text to ""
write midhtml to the file ((startblock as string) ¬
& "fullindex.html") starting at eof
end tell
end makefileitem
on fixindex()
display progress "Making Index Files" subtitled "Progress..." value 0
set myindexfile to ((startblock as string) & "fullindex.html")
set theindex to read myindexfile
set eof of the myindexfile to 0
write ¬
"<HTML><HEAD><TITLE>Index</TITLE>
</HEAD><BODY BGCOLOR=\"#FFFFFF\"><H1>Compiled Index</H1>
<TABLE BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"1\">" to ¬
myindexfile starting at 0
write theindex as string to file ((startblock as string) & "fullindex.html") ¬
starting at eof
write ¬
"</TABLE></BODY></HTML>" to myindexfile starting at eof
end fixindex
Version 2 - for specified folder
-- Properties
property kasHtHead : {"<HTML>", "<HEAD>", "<TITLE>", "Index", ¬
"</TITLE>", "</HEAD>", "<BODY BGCOLOR=\"#FFFFFF\">", ¬
"<H1>", "Index Results", "</H1>"}
property kasHtTail : {"</BODY>", "</HTML>"}
property kasTblHead : {"<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=2>"}
property kasRowHead : {"<TR>", "<TD VALIGN=top>"}
property kasRowDiv1 : {"</TD>"}
property kasRowTail : {"</TR>"}
property kasTblTail : {"</TABLE>"}
property linklead : {"http://"}
property serverhead : {"ip address such as 17.254.0.91 ¬
or domain name such as www.apple.com/"}
property frontlink : {"<A HREF="}
property endlink : {"</A>"}
property kasName : {"Index"}
property fsObjs : {"file path such as Macintosh HD:Web Pages:"} as alias
-- Globals
global gasFoldersToDo -- The folders left to process
on run
tell application "Finder"
if exists file ((fsObjs as string) & "fullindex.html") then
deleteFile ((fsObjs as string) & "fullindex.html")
a new file in fsObjs named "fullindex.html"
else
a new file in fsObjs named "fullindex.html"
end if
end tell
open {fsObjs}
fixindex()
display progress "Making Index Files" subtitled "Progress..." with disposal
end run
on open (fsObjs)
set total to (number in (the entries in fsObjs to a depth of -1)) / 3
set pw to display progress "Making Index Files" subtitled "Progress..." maximum total
-- Do files
set gasFoldersToDo to {}
repeat with fsObj in fsObjs
set myInfo to (basic info for fsObj)
if (file type of myInfo is "fold") then
set gasFoldersToDo to gasFoldersToDo & {fsObj}
end if
end repeat
-- Do folders
repeat while gasFoldersToDo is not {}
-- Pop one off the end
set n to the number of items of gasFoldersToDo
set fsObj to item n of gasFoldersToDo
if (n > 1) then
set gasFoldersToDo to items 1 ¬
through (n - 1) of gasFoldersToDo
else
set gasFoldersToDo to {}
end if
-- Process it
DoOne(fsObj)
GoDeep(fsObj)
end repeat
end open
on DoOne(fsObj)
makefileitem(fsObj)
end DoOne
on GoDeep(foldObj)
set daddy to foldObj as string
-- Do folders
set myItems to the entries in foldObj ¬
whose kinds are a folder
repeat with myItem in myItems
set gasFoldersToDo to gasFoldersToDo & ¬
{(daddy & myItem) as alias}
end repeat
end GoDeep
on makefileitem(fsObj)
display progress "Making Index Files" subtitled "Progress..." value 0
tell application "Finder"
try
set theFiles to (the entries in fsObj as alias ¬
whose kinds are a file whose labels are in 0)
end try
set target_file_path to (fsObj) & "index.html"
set |html| to kasHtHead & kasTblHead
repeat with theFile in theFiles
if theFile's name is not in {"index.html", "fullindex.html"} then
set ciName to munge the theFile ¬
as string from fsObjs as string to ""
set toplink to linklead & serverhead & ¬
{munge ciName from ":" to "/"} as text
set toplink to munge ¬
toplink as string from " " to "%20"
set mainlink to frontlink & toplink & ">" as text
set justName to mainlink & ¬
(munge (theFile as string) from ¬
(fsObj as string) to "") & endlink as text
set |html| to |html| & kasRowHead & ¬
justName & kasRowDiv1
end if
end repeat
set listhtml to |html| & kasRowTail & kasTblTail & kasHtTail
set htTxt to compile ML listhtml
set the target_file_path to the target_file_path as text
set the open_target_file to open for access ¬
the file target_file_path with write permission
set eof of the open_target_file to 0
write htTxt to the open_target_file starting at eof
close access the open_target_file
set theFolders to (the entries in fsObj ¬
as alias whose kinds are a folder)
repeat with thefolder in theFolders
set ciName to munge ¬
the thefolder as string from fsObjs as string to ""
set toplink to linklead & serverhead & ¬
{munge ciName from ":" to "/"} as text
set toplink to munge toplink as string from " " to "%20"
set mainlink to frontlink & toplink & ">" as text
set nocolfol to munge (thefolder as string) from ":" to ""
set nocolobj to munge (fsObj as string) from ":" to ""
set justName to mainlink & (munge nocolfol from nocolobj to "") ¬
& "/" & endlink as text
set |html| to |html| & kasRowHead & justName & kasRowDiv1
end repeat
set listhtml to |html| & kasRowTail & kasTblTail & kasHtTail
set htTxt to compile ML listhtml
set the target_file_path to the target_file_path as text
set the open_target_file to open for access ¬
the file target_file_path with write permission
set eof of the open_target_file to 0
write htTxt to the open_target_file starting at eof
close access the open_target_file
set midhtml to listhtml
set midhtml to munge ¬
midhtml as string from kasHtHead as text to ""
set midhtml to munge ¬
midhtml as string from kasTblHead as text to ""
set midhtml to munge ¬
midhtml as string from kasTblTail as text to ""
set midhtml to munge ¬
midhtml as string from kasHtTail as text to ""
write midhtml to the file ((fsObjs as string) ¬
& "fullindex.html") starting at eof
end tell
end makefileitem
on fixindex()
set myindexfile to ((fsObjs as string) & "fullindex.html")
set theindex to read myindexfile
set eof of the myindexfile to 0
write ¬
"<HTML><HEAD><TITLE>Index</TITLE>
</HEAD><BODY BGCOLOR=\"#FFFFFF\"><H1>Compiled Index</H1>
<TABLE BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"1\">" to ¬
myindexfile starting at 0
write theindex as string to file ((fsObjs as string) & "fullindex.html") ¬
starting at eof
write ¬
"</TABLE></BODY></HTML>" to myindexfile starting at eof
end fixindex
Last updated: 3/16/00
Laine Lee
E-Mail: llee@txdirect.net