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)

“~/Desktop/test.scpt”

Mac output path:

“Machintosh HD:User:UserName:Desktop:test.scpt”

Any help is much appreciated!

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

file://host/path

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
	else
		return posixPath
	end if
end expand_tilde

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