Tuesday, December 12, 2017

#1 2016-04-06 11:51:47 am

stegor
Member
Registered: 2006-03-07
Posts: 45

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.

Applescript:


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.


Filed under: url, path control

Offline

 

#2 2016-04-06 11:59:17 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Path control won't take my URL

Hi,

I recommend to create a real NSURL

Applescript:

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


regards

Stefan

Offline

 

#3 2016-04-06 01:03:44 pm

stegor
Member
Registered: 2006-03-07
Posts: 45

Re: Path control won't take my URL

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!

Offline

 

#4 2016-04-06 01:19:07 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Path control won't take my URL

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

Applescript:

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


regards

Stefan

Offline

 

#5 2016-04-06 07:04:41 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: Path control won't take my URL

StefanK wrote:

It's still easier: AppleScript alias is implicitly bridged to NSURL


But only in 10.11...


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)