Space in Volume name causing issue with "get file"

I have a script that gets the filename/path of a open text file. The file is located on a drive that has a space in the volume name and this is breaking my script. How can I escape spaces when I am using get file to retrieve the path?

tell application "BBEdit" to get file of first text window

Are you sure the space is the problem? I’ve just tested using a file in a folder with a space in its name and it worked fine. My test was with OS X 10.7.4 and BBEdit 10.1.2

This is my whole script:

property phpref : "/usr/bin/php -l "
try
	tell application "BBEdit" to get file of first text window
	do shell script phpref & POSIX path of result
	display dialog "Ok: " & result buttons {"finished checking"} default button 1
on error msg
	display dialog "Err: " & msg buttons {"finished checking"} default button 1
end try

It is showing this error: Could not open input file: /Volumes/Data

The volume name is “Data HD” so I thought the space was the problem.

Your problem is in this line…

do shell script phpref & POSIX path of result

Chang it to this…

do shell script phpref & quoted form of POSIX path of result

On the command line spaces are used to separate arguments so it sees the space in the path name as just that. You fix that by putting quotes around the path.

That did it. Thank you!

Just to sum up, this is the final script to add PHP validation to BBEdit 10.

property phpref : "/usr/bin/php -l "
try
	tell application "BBEdit" to get file of first text window
	do shell script phpref & quoted form of POSIX path of result
	display dialog "Ok: " & result buttons {"Finished Checking"} default button 1
on error msg
	display dialog "Err: " & msg buttons {"Finished Checking"} default button 1
end try