Question about file paths and variables

I have a problem with identifying a file by variable.

The first part is that I fill a popup menu with a list of files from a folder. The folder is identified thru an open panel, then I do this:

on loadFileList()
	--Load the list of files from the folder
	tell application "Finder"
		set filePath to ((POSIX file defaultFilePath) as alias)
		set fileList to ((name of every file) of folder filePath as list)
	end tell
	--load the file list into the popup menu
	tell window "SelectWindow"
		delete every menu item of menu of popup button "SelectFilePop"
		repeat with tmpItem in fileList
			make new menu item at the end of menu items of menu of popup button "SelectFilePop" with properties {name:tmpItem, title:tmpItem, enabled:true}
		end repeat
	end tell
end loadFileList

Then the window appears and the user selects the file from the popup. this script runs:

tell application "TextEdit"
	--set the path to the file:
	set the thePath to ((defaultFilePath) & ":" & selectedFile) as string
	log thePath
	open alias thePath			
end tell

This fails with the error “File doesn’t exist.” If I replace the variable ((defaultFilePath) &“:”& selectedFile) with the literal path as a string it works?

What am I doing wrong?


I found the solution.

I changed it to:

open alias ((POSIX file (defaultFilePath & "/" & selectedFile)) as string)

and no more error. don’t really know why this works.