"kind of" sometimes empty if a folder on a server

I have a script which is called as an Automater plugin. I’m not sure if this matters, but the script is not embedded in the workflow due to some complexities in the script. Rather, there is a “Get Specified Finder Items” passed to an “Open Finder Items” which specifies the script as the “Open with” application.

Anyway, in the script there is a test on the kind of the selected item to see if it is a folder:


on open inPut
	set deBug to 1
	tell application "Finder"
		set theObject to inPut as alias
		set myKind to kind of theObject
		if deBug > 0 then display dialog "myKind[3]: " & myKind
		if myKind is "Folder" then
			set myURL to URL of theObject
		else
			set myURL to URL of container of theObject
		end if
		. . .

Here’s where it gets weird: After selecting a folder on a server (I’ve tried AFP servers and SMB servers) the first time the script is run, “myKind” ends up blank. If the script is run again on the same selection, “myKind” returns “folder”. If I select another folder, the first time the script is run, myKind is again blank, but returns “folder” if it is run again without changing the selection.

This doesn’t seem to happen if the selection is a file of some sort. If also doesn’t happen if I select a folder on a volume that is local to my computer.

Any ideas?

T.

Hi,

to access a file or folder on a shared volume I recommend to avoid the Finder as much as possible.
You can also check a folder coercing the alias to its POSIX path.
If the item is a folder, there’s a slash character at the end

on open inPut – inPut is always a list of aliases!
set deBug to 1
repeat with oneItem in inPut
set theObject to POSIX path of oneItem
if theObject ends with “/” then
tell application “Finder” to set myURL to URL of oneItem
else
tell application “Finder” to URL of container of oneItem
end if
– do something
end repeat
end open