Re: adding links to html pages
Re: adding links to html pages
- Subject: Re: adding links to html pages
- From: David Hood <email@hidden>
- Date: Mon, 21 Jul 2003 17:05:00 +1200
This uses the OS X command line (and python) to add a link to
http://www.somewhere.etc before the closing body tag. It just needs to
be altered to repeat with every file in a folder whose name ends with
html (or htm). If you want the link at the top of the page, look for
the open body tag.
----------------
set nl to (ASCII character 10) --unix newline ending
set cr to (ASCII character 13) --mac newline ending
set bq to "\"" --backslashed doublequote for readibility
set anyoldfile to choose file
set unixFriendly to quoted form of POSIX path of anyoldfile
set ptext to "import string
f=open(" & unixFriendly & ",'r+')
something=f.read()
somethingelse = string.replace(something, '</BODY>','<P><A
HREF=\\\"
http://www.something.etc\\\"> home</A></P></BODY>')
f.write(somethingelse)
f.close()"
set ptext to newImprovedText(ptext, cr, nl)
set pythonCommand to "python -c " & bq & ptext & bq
do shell script pythonCommand
--for correcting line endings
on newImprovedText(offeredText, Fromsomething, Tosomething)
set saveddelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to Fromsomething
set listOfText to every text item in offeredText
set AppleScript's text item delimiters to Tosomething
set newString to listOfText as string
set AppleScript's text item delimiters to saveddelimiters
return newString
end newImprovedText
----------------
Regards,
David H.
_______________________________________________
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.