Path control won't take my URL

I’ve done this before without a problem so I can’t figure out what is wrong here.


    on theChooseFolder_(sender)
        set theLocalFilepath to (choose folder)
        
        tell application "Finder" to set theLocalFileURL to URL of theLocalFilepath

        log theLocalFileURL

        theLocalFilepathWidget's setURL_(theLocalFileURL)
    end theChooseFolder_

2016-04-06 11:35:28.866 Model Updater[7799:303] file:///Users/user/Documents/
2016-04-06 11:35:28.869 Model Updater[7799:303] *** -[ZYXAppDelegate theChooseFolder:]: *** -[NSURL initWithScheme:host:path:]: path file:/Users/user/Documents is not absolute. (error -10000)

It seems to me theLocalFileURL is a URL, but when I try to set the URL of the path control I’m told it’s not absolute.

Hi,

I recommend to create a real NSURL

set theLocalFilepath to (choose folder)
set theLocalFileURL to current application's |NSURL|'s fileURLWithPath:(POSIX path of theLocalFilepath)

I was getting close - I tried that earlier but I left out the “POSIX path” part. It worked but I got the path to the application itself with the chosen path at the end. I wasn’t expecting that.

This works great. Thanks!

It’s still easier: AppleScript alias is implicitly bridged to NSURL, there is no need at all for extra work

set theLocalFilepath to (choose folder)
theLocalFilepathWidget's setURL:theLocalFilepath

But only in 10.11…