Get parent folder of file(s) (using container)

I’m trying to bring this little script into ApplescriptObjC

At the moment I get an error that I can only assume is to do with the alias? But i’m not sure how to correct this.

set resultFiles to (choose file with prompt "Please select images:" with multiple selections allowed without invisible) -- list of aliases
set firstFile to first item in resultFiles's contents
log firstFile

tell application "Finder" to set fileLocation to container of firstFile

set resultFilesFolder to (fileLocation as string)

Hi mcquiff,

This works:

set resultFiles to (choose file with prompt "Please select images:" with multiple selections allowed without invisible) -- list of aliases
set firstFile to (item 1 in resultFiles) as string
tell application "Finder" to set pathFolderParent to (folder of item firstFile) as string

Stefano - Ame

Hi,

the AppleScriptObjC equivalent is


set openPanel to current application's NSOpenPanel's openPanel()
openPanel's setMessage:"Please select images:"
openPanel's setShowsHiddenFiles:false
openPanel's setAllowsMultipleSelection:true
set returnCode to openPanel's runModal() as integer

if returnCode = (current application's NSFileHandlingPanelOKButton) as integer then
	set firstFile to openPanel's URLs()'s firstObject()'s |path|()
	set resultFilesFolder to firstFile's stringByDeletingLastPathComponent() as text
end if

but there is one important difference:
the result in AppleScript is an HFS path
the result in AppleScriptObjC is a POSIX path

Hmmm still struggling,

I’m selecting a list of files. these all come from the same folder. then I am trying to extract the parent folder path, so that I can display it in a text box. Purely to indicate that files have been selected.

I’m following Ben Waldie’s tutorial here http://www.peachpit.com/articles/article.aspx?p=1959674&seqNum=3.

With the script above, there are no errors but still nothing showing in the text box.

The AppleScriptObjC code works. I’ve tested it. The variable resultFilesFolder contains the POSIX path to the parent folder of the first selected file.

I’ve got it working, I was using the same code but I needed it to be case sensitive

on loadedFiles_(sender)
        set resultFiles to (choose file with prompt "Please select images:" without invisible with multiple selections allowed) -- list of aliases
        set firstFile to first item in resultFiles's contents
        tell application "Finder" to set fileLocation to container of firstFile
        setResultFilesFolder_(fileLocation as string)

    end loadedFiles_

Not sure why your code did’t work, I may not have bound it correctly.