POSIX file problems in AS Studio that I can't recreate in Script Edito

So, I have an Applescript Studio app that I’m developing (Xcode 2.1, OS X 10.4.2), and one of the things I need to do is verify whether or not a certain user specified directory (specified through the open panel) has a CVS directory inside it.

I’ve got some script like this (snipped a bit for clarity


property localFolder: ""
-- when panels (i.e. open, save) are ended (closed)
on panel ended eventTarget with result panelResult
	if eventTarget is the open panel then
		if panelResult is 1 then -- checking cancel wasn't pressed
			set localFolder to item 1 of (path names of open panel as list)
		end if
	end if
end panel ended
-- later on, 
on checkForCVS()
	set CVSWorkingFolder to POSIX file of localFolder
	-- result is an app error: Can't get POSIX file of "/Users/matt/Emdash/Jobs". (-1728)
	-- This is a perfectly valid path: copy and paste it into the Finder's Go to Folder 
end checkForCVS

The -1728 error that results from the set CVSWorkingFolder to POSIX file of localFolder is just weird: I picked a folder using the open panel, the result ought to be a valid path… And, as far as the error goes the path it’s reporting is definitely real.

Does anyone have any idea why this is happening? The Script Editor equivalent (choose folder) returns an alias, and that works fine. Frankly, I’m baffled. I hope it’s just that I’m doing something dumb…

Thanks,

Matt

The problem is the “POSIX file” command, which is unrelated to the choose folder command.

Try removing the “of”:

set CVSWorkingFolder to POSIX file localFolder

You’ll see this mentioned breifly in TN2065.

Edit: This works correctly in Script Editor (look in the Event Log). Try adding a “of” after “POSIX file” and see what happens.

choose folder
set test to result

set test to POSIX path of test
log result

set test to POSIX file test
log result

return test

Yeah, that was dumb thing number 1. I’d had the correct form in earlier, but there were other problems and I changed it.

Kind-of dumb thing, and the main cause of the problem was that I had this code:


on handlerName()
	set CVSWorkingFolder to POSIX file localFolder
end handlerName()

And that was throwing a -1700 error - a coercion error, in other words.

That was weird, but then I looked up at my code and realised that actually, this was what was happening


on handlerName()
	tell view of tab view item "local copy - tab item" of tab view "main - view" of window "main"
		set enabled of button "check out - local" to true
		-- local tab commit (also needs a check out to have occured)
		set checkedOut to false
		set CVSWorkingFolder to POSIX file localFolder
		set CVSList to list folder CVSWorkingFolder
	end tell
end handlerName()

The code was executing in the context of a view, I (in desperation more than anything else) altered the code to enclose the POSIX file line in a tell block of its own:


on handlerName()
	tell view of tab view item "local copy - tab item" of tab view "main - view" of window "main"
		set enabled of button "check out - local" to true
		-- local tab commit (also needs a check out to have occured)
		set checkedOut to false
		tell application
			set CVSWorkingFolder to POSIX file localFolder
		end tell
		set CVSList to list folder CVSWorkingFolder
	end tell
end handlerName()

That worked fine then. Which was a relief. I don’t know why that tell block made such a difference, but there you go. Interestingly, if you put the set CVSList to list folder CVSWorkingFolder line inside the tell application block then you get this error:

application doesn't understand the «event earslfdr» message. (-1708)

If anyone wants to enlighten me on the whys and wherefores of all this, I’d be delighted.

Matt