Monday, July 16, 2018

#1 2010-08-24 04:16:40 pm

jamesnw
Member
Registered: 2008-12-14
Posts: 9

NSPathControl to POSIX file with spaces

I'm trying to get a value from a NSPathControl in my XIB and change it into a POSIX file, so I can manipulate it in the Finder (make a copy, rename, etc). My code works, but not if there are any spaces in the path. Any spaces are returned as %20, which doesn't translate into a POSIX file. Any ideas?

Applescript:


on clicked theObject
   set theFile to (string value of control "sourceXML" of window "main")
   set theFile to (theFile as POSIX file)

   tell application "Finder"
   reveal theFile
   end tell
end clicked

Offline

 

#2 2010-08-25 03:36:34 am

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

Re: NSPathControl to POSIX file with spaces

Hi,

the path control returns an NSURL object, you can coerce it to a string path by calling a method of NSURL class

Applescript:


on clicked theObject
   set theFile to (string value of control "sourceXML" of window "main")
   set URLObject to call method "URLWithString:" of class "NSURL" with parameter theFile
   set theAlias to POSIX file (call method "path" of URLObject) as alias
   tell application "Finder"
       reveal theAlias
   end tell
end clicked


regards

Stefan

Offline

 

#3 2010-08-25 09:57:08 am

jamesnw
Member
Registered: 2008-12-14
Posts: 9

Re: NSPathControl to POSIX file with spaces

Thanks, Stefan, That works great!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)