Newbie: How to open htm with applescript?

I’m a newbie to applescript, so hoping that someone can help.
I want to write a text file to the user’s home folder (which I can do already) but after that, I want to launch a webpage. The webpage is placed in the same directory where the applescript application is. Can someone tell me why the following doesn’t work?


set the_file to (((path to home folder) as string) & "testing.txt") as file specification

set the_data to "testing 123"

try
	open for access the_file with write permission
	set eof of the_file to 0
	write (the_data) to the_file starting at eof
	close access the_file
on error
	try
		close access the_file
	end try
end try

tell application "Finder"
	open "start.htm"
end tell

What do you mean by “doesn’t work”? What happens? What error do you get?

Do the part that creates the file. Then find it on the hard drive. Did it work? If not, telling applescript to open it won’t work either. Try a .html extension. Try telling Safari to open the file instead of the finder.

im not exactly experienced, but have you tried instead of opening it with the Finder opening it with safari?

tell application "Safari" to open "file.htm"

I think you need to specify the full path to the file, whether it is a URL or a file.

Instead of having the Finder opening the file, use the standard additions command “open location”. This will open in your default browser.
If the file is on your harddrive:

open location "file://Macintosh Hard Drive:Path:to:file:start.htm"

If the reference is a URL:

open location "http://domain.net/start.htm"

Of course if you just want to open the file to edit it you can use (free!) Text Wrangler:

tell app "Text Wrangler"
   open file "MacHD:Path:to:file:start.htm"
end tell

You see that you still need to use the full path to the file.

Thanks all for the reply.
Yeah, i guess i must specify the full path coz i get the error "Finder cannot get the file “start.htm”.
My problem is that the folder containing the script and the webpage can be anywhere on the user’s harddisk or even on CD. How do I get the full path to the folder from which the script was launched? Or alternatively, is it possible to specify a relative path like html links?

path to me

give you the path to your script. You can work back from there.

Thanks alot.
Path to me did the trick.
i finally got it working. :smiley: