Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Here's a generic function to replaces strings within a string:

Code:
on replaceString(theText, oldString, newString)
	set AppleScript's text item delimiters to oldString
	set tempList to every text item of theText
	set AppleScript's text item delimiters to newString
	set theText to the tempList as string
	set AppleScript's text item delimiters to ""
	return theText
end replaceString

However, in AppleScript I think you could just coerce it from a POSIX path to an HFS-style string (which uses colons as path separators):

Code:
POSIX file ("Your/full/unix/path/here") as string

...which results in...

Code:
":Your:full:unix:path:here"

I guess you would then just take everything except the first character to remove the leading colon.
 
However, in AppleScript I think you could just coerce it from a POSIX path to an HFS-style string (which uses colons as path separators):

Code:
POSIX file ("Your/full/unix/path/here") as string

...which results in...

Code:
":Your:full:unix:path:here"

I guess you would then just take everything except the first character to remove the leading colon.

The HFS-style pathname shown is in exact correspondence to the Posix-style pathname. Both are relative pathnames: they refer to a subpath relative to the working directory.
http://en.wikipedia.org/wiki/Working_directory

Leading-colon means "relative path" and no-leading-colon means absolute in HFS-style. Leading-slash means "absolute path" and no-leading-slash means relative in Posix-style.

So if you removed the leading colon, you'd have a completely different meaning. It would correspond to "/Your/full/unix/path/here".

Other than that, the suggestion is correct: let the system do the pathname conversion. And if the code needed an alias reference, then "as alias" is more suitable than "as string".
 
The HFS-style pathname shown is in exact correspondence to the Posix-style pathname. Both are relative pathnames: they refer to a subpath relative to the working directory.
http://en.wikipedia.org/wiki/Working_directory

Leading-colon means "relative path" and no-leading-colon means absolute in HFS-style. Leading-slash means "absolute path" and no-leading-slash means relative in Posix-style.

So if you removed the leading colon, you'd have a completely different meaning. It would correspond to "/Your/full/unix/path/here".

Yes, except the OP specifically showed in his example that he wanted the leading colon removed (why, I don't know, maybe he has some other use for that form).
 
Yes, except the OP specifically showed in his example that he wanted the leading colon removed (why, I don't know, maybe he has some other use for that form).

The OP specifically said he had:
... a file path in the "/Users/admin/Desktop" format, but I need a "Users:admin: Desktop format.

Note the leading slash on the Posix-style path, underlined above. Since "leading slash" corresponds to "no leading colon", and means "absolute pathname", the OP will get a path without a leading colon if he uses the Posix file class in the recommended way.

If the OP does need to remove anything, it will be the name of the boot drive, not simply a leading colon. Because given the Posix path he's starting with, he will get an initial drive-name, as in "MacHD:Users:...", not the "Users:..." pathname he thinks he will be getting.

I suggest verifying this by simple testing with the Posix file class in AppleScript Editor.app:
set pathname to "/Users/Shared"
set p2 to Posix file pathname
return (p2 as alias)


I realize I made an error in saying "Your:path:here" corresponded to "/Your/path/here". Absolute HFS-style pathnames always start with a drive-name and no colon. Absolute posix-style pathnames always start with a "/" and may or may not include anything resembling a drive-name. Correspondence can be a tricky business, so it's best to let the Posix path and alias classes handle it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.