Saturday, November 27, 2021

#1 2021-11-16 02:51:47 am

Registered: 2021-04-16
Posts: 40

convert URI path to Mac path

Hi all,

how to convert the below URI path to Mac Path

URI path:(the path returns from the Javascript UI file selection)


Mac output path:

"Machintosh HD:User:UserName:Desktop:test.scpt"

Any help is much appreciated!



#2 2021-11-17 02:09:28 pm

From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 518

Re: convert URI path to Mac path

I don't think you're asking about a URI, those look like this:


From the example paths in your question, you just want to convert a POSIX path to an HFS path, including tilde expansion.

There are many ways to do this, including using shell to expand the tilde or using AsObjC to do it, but here's a simple all-Applescript way:


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

set aPath to "~/Downloads"
set expandedPosixPath to expand_tilde(aPath)
set HFSpath to (POSIX file expandedPosixPath) as alias as text

on expand_tilde(posixPath)
   if posixPath starts with "~" then
       set homePath to POSIX path of (path to home folder as alias)
       set remainingPath to text 3 through end of posixPath
       set combinedPath to homePath & remainingPath
       return combinedPath
       return posixPath
   end if
end expand_tilde

Last edited by t.spoon (2021-11-17 02:11:00 pm)

Ditched the Hackintosh.
Intel Mac Mini i7 and M1 Mac Mini on a KVM.



#3 2021-11-18 01:45:48 am

Registered: 2021-04-16
Posts: 40

Re: convert URI path to Mac path

Thank you so much for the update. I will check:)



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)