• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Convert File or Path Input into NSURL, HFS path, or POSIX Path Output
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convert File or Path Input into NSURL, HFS path, or POSIX Path Output


  • Subject: Re: Convert File or Path Input into NSURL, HFS path, or POSIX Path Output
  • From: Christopher Stone <email@hidden>
  • Date: Wed, 01 Mar 2017 04:48:23 -0600

On Feb 28, 2017, at 16:59, Shane Stanley <email@hidden> wrote:
    # return myNSURL as text -- HFS path
  return POSIX path of (myNSURL as text)

FWIW, I'm surprised those two work -- you shouldn't be able to coerce an NSURL to text.
…
If you want the POSIX path, you should use the path method.


Hey Folks,

By path method he means this:

-------------------------------------------------------------------------------------------

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set folderPath to POSIX path of (path to downloads folder)

--> "/Users/myUserName/Downloads/"

set myNSURL to current application's |NSURL|'s fileURLWithPath:folderPath
set myFolderPath to myNSURL's |path|() as text -- without the as text coercion you have a NSString

--> "/Users/myUserName/Downloads"

-------------------------------------------------------------------------------------------

This scriptlet if of course redundant.

But you may process a NSURL a great deal before finally outputting a path, and this gives you the bones to do it.

--
Best Regards,
Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: RE: Scripting Better Applescript support requests !
  • Next by Date: collectdata
  • Previous by thread: Re: Scripting Better Applescript support requests !
  • Next by thread: collectdata
  • Index(es):
    • Date
    • Thread