newbie question....

Hi,

I’ve just got my first mac today (a new MacBook Pro no less)…

Being a web developer I’ve been busy installing php and mysql etc - all this is working fine.

Then I thought wouldn’t it be nice if I could create a script that changes the document root of apache to the folder that I drop onto it…

I’ve got so damn close it’s killing me! -

From hunting around I’ve got a script that restarts apache. A script that writes to a text file and a script that does something to do with a folder that’s been dropped on it.

I’ve got a small httpd.conf file that gets included in the proper main httpd.conf file - so I can clear it and write to it from my applescript. Then restart apache and it’s working.

Problem is that my script writes to my small httpd.conf file with a space - " " between each character. This only happens when I translate the folder path using the POSIX command AND add it to my string before writing to my conf file. If I don’t do the POSIX command or I don’t add the resulting string to my Virtual host string then there’s no double spacing… Any clues helpful.

here’s my script (no apache restart code in there yet, that’s just one line anyway)




on open input
	tell application "Finder" to set thePath to POSIX path of (item 1 of input as text)
	setFolderToBeApacheRoot(thePath)
end open

on setFolderToBeApacheRoot(filePath)
	set firstPart to "<VirtualHost localhost:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "
	set lastPart to "
    ServerName localhost
</VirtualHost>
"

	set str to firstPart & filePath & lastPart
	set this_file to "/path/to/include/httpd.conf"
	set this_file to POSIX file this_file
	display dialog this_story
	my write_to_file(str, this_file, false)


end setFolderToBeApacheRoot

on write_to_file(this_data, target_file, append_data)
	try
		set the target_file to the target_file as text
		set the open_target_file to ¬
			open for access file target_file with write permission
		if append_data is false then ¬
			set eof of the open_target_file to 0
		write this_data to the open_target_file starting at eof
		close access the open_target_file
		return true
	on error
		try
			close access file target_file
		end try
		return false
	end try
end write_to_file

Welcome to the wonderful (and sometimes frustrating) world of Apple.

From what it sounds like, you’re having issues going back and forth from double-byte (Unicode) to single-byte ASCII text, etc.

Check out http://bbs.applescript.net/viewtopic.php?id=13201 for a tip. Also, HHAS has replied dozens of times about the matters of text encoding, character sets, etc.

-N

excellent - thanks for that - I didn’t quite tear my hair out!