Convert hfs to uri path

I was wondering to find no relevant topics online,
about how to convert hfs paths into an uri paths.
Ideally I look for a code wrap to insert paths as links in applications which support this features, of course.
Thanks for any suggestion

You can use System Events:

set aFile to path to desktop
tell application id "com.apple.systemevents" -- System Events.app
	set theURI to URL of aFile
end tell

You can also use the Finder for this.

set aFile to path to desktop
tell application "Finder" to set theURI to URL of item aFile

Works great!
At this point a curious question: is it possible to convert local files (uri- files) to URL files? I think it makes no sense because uri files are local URLs… And conventional URLs are online -not local- files.

URLs are URLs. They start always with a scheme, for example

  • Local file URLs start with file://
  • Remote URLs start with http:// or https://
  • FTP URLs start with ftp://
  • URLs to launch AppleScripts from web pages start with applescript://

and so on.

On the other hand a POSIX path is a file URL without the file:// scheme