automate (Add code to html) Text Wrangler

Hi everyone

I ve been asked to look into adding a line of
code to a html page which gets uploaded to our server
weekly. The line of code is the same each week
and appears at the top of a html page exported from
excel. This code is an automatic refresh script so when internal
staff access the site there browsers refresh without them
clicking the refresh button.

here is the code added:

I am trying to create an automated version of this
to include in the action before this is uploaded.

At the moment I can export excel file to html
using automator and upload via transit all in one action
But maybe I can edit html page to add this line of
code before I upload to the server.

any help or advice would be grateful

lister

Browser: Firefox 3.0.4
Operating System: Mac OS X (10.5)

I cannot locate any Text Wrangler Automator Actions out there, but you should be able to do this with a simple Run AppleScript action, so long as you know where the text needs to be inserted into each file. This is one way to do it with a file located on the desktop:

set theFile to open for access file ((path to desktop as text) & "Other_Dates.html") with write permission

set theFileContents to read theFile
set newContents to "<meta http-equiv=\"refresh\" content=\"30\" />" & return & theFileContents

write newContents to theFile starting at 0
close access theFile

Hope this helps,

sorry for my lack of knowlege in applescript:

if the filename of the html is called schedule.html and is saved onto the desktop
and the path to the dektop is called

Macintodh HD/Users/media/Desktop/schedule.html

Do i edit the below line before I save this as a script> The added peice of code ‘’
will always appear under on the schedule.html

set theFile to open for access file ((path to desktop as text) & “Other_Dates.html”) with write permission

Thanks for your help…

lister

lister:

No problem. I was not aware that you needed the line right after the , so I changed the script a bit, and if you paste this into your Run AppleScript action, and the schedule.html file is on the desktop, it should work:

set theFile to open for access file ((path to desktop as text) & "schedule.html") with write permission
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "<head>"
set theFileContents to read theFile
set newContents to (theFileContents's text item 1) & "<head>" & return & "<meta http-equiv=\"refresh\" content=\"30\" />" & return & (theFileContents's text item 2)
write newContents to theFile starting at 0
close access theFile
set AppleScript's text item delimiters to astid

I believe this should work, even if there is nothing in front of the in the file, but I am not sure about that. Try it out and see what happens.

Good luck,

Wow that works a treat, just one more question…sorry… if the file gets saved into a folder called upload and is always on my desktop
how can I edit the right directory in the script to mirror this path?

Thanks again for your help…

This line defines the location of the file in question:

set theFile to open for access file ((path to desktop as text) & "schedule.html") with write permission

This portion of that line defines the actual file:

((path to desktop as text) & "schedule.html")

When the script runs, that portion is interpreted thusly (on the machine I am using; everyone else’s results will be different):
“Barney:Users:cynthiasmith:Desktop:schedule.html”

So, you can see that colons are used as separators in a path structure. For a folder on your Desktop entitled upload, you would want your interpreted result to look similar to this:
“Barney:Users:cynthiasmith:Desktop:upload:schedule.html”

You can achieve that by altering the file definition this way:

((path to desktop as text) & "upload:schedule.html")

Good luck, hope this helps,

Thanks so much for your help… I really appreciate it!

Take care