Macro to convert paths for different scenarios

I'm building a simple macro to convert a path to use in different scenarios.
For example I'm considering 3 types:
path:to:file A
path/to/file\ A
path/to/file A

So I just want to know a few things:
1 - I noticed that all examples using : start with the name of the volume like this:
Macintosh HD:Users:yourUserName:Desktop:My File.txt, but when I copy a path from Finder, it starts with /Users. Will it make a difference if I have a path like this without the volume name?
Users:yourUserName:Desktop:My File.txt

2 - The colon-delimited path is just the full path, but where the / becomes :, right? Even if I have spaces, all I need to do is convert / to :, right?
So this:
Macintosh HD/Users/yourUserName/Desktop/My File.txt
becomes this:
Macintosh HD:Users:yourUserName:Desktop:My File.txt
?

3 - For both of these versions I have to use double quotes because of the spaces (if any, of course), but for the spaced spaces, no need for that, right?
Like this:
"Macintosh HD/Users/yourUserName/Desktop/My File.txt"
"Macintosh HD:Users:yourUserName:Desktop:My File.txt"
Macintosh HD/Users/yourUserName/Desktop/My\ File.txt

4 - Can I also escape the spaces on a colon-delimited path like this?
Macintosh HD:Users:yourUserName:Desktop:My\ File.txt

For Posix file path conventions vs AppleScript alias strings, see:

Mac Automation Scripting Guide: Referencing Files and Folders

Yes, that's the website I got this info from.
But it doesn't answer some of my questions, not to mention that the language there is very specific and I'm not on that level yet to fully understand what's being said

  1. Volume name is required only by the AppleScript format. Full Posix paths start at the file-system root, which is just /
  2. As you say, below the root, the posix separator / maps onto the AppleScript :
  3. ("Can I") Nothing stops you, but the result depends on the evaluating context. It depends on how exactly you are using these strings, and what is reading them.

Rather than hand-written string processing, you would probably get better results from less work by starting with a valid AppleScript alias or file reference, and letting AppleScript itself generate the Posix-compliant or colon-delimited path strings.

(But I'm not yet very clear about the context here – we may need to back out of an XY problem to get more clarity and a better result for you)

2 Likes