NSURL directory key

I’m trying to automate some tasks that I need to apply only to directories. I’m not necessarily new to coding, but very new to applescript, and OS X in general.

The code I have is:

set {isFileResult, isFile} to aURL's getResourceValue:(reference) forKey:(current application's NSURLIsDirectoryKey) |error|:(missing value)

Regardless of whether the URL passed in is a file or a directory, this always returns true. Any pointers would be greatly appreciated. I’m having a difficult time finding any documentation that would help me access the keys of an NSURL in a confident manner.

Thanks,
Mike

Hi,

basically the code is correct.
Did you create the NSURL instance with fileURLWithPath ? For URLs on disk you have to.

Be aware that the return value isFile (actually isDirectory) contains an NSNumber object, to use the scalar boolean value call boolValue() and to process it in AppleScript append as boolean

on attachScriptToNewFolder:someString forPath:posixPath
	set aURL to current application's |NSURL|'s fileURLWithPath:posixPath
	set {isDirectoryResult, isDirectory} to aURL's getResourceValue:(reference) forKey:(current application's NSURLIsDirectoryKey) |error|:(missing value)
	if isDirectory then

Here is the relevant code (corrected variable names to make sense). I actually figured out the issue, my problem was in my testing code.

Thank you for your input on it though.

–Mike

better write

if isDirectory as boolean then

to cast the Cocoa type to an AppleScript type