get the name of the parent folder

@Nigel

Thank you.
I had doubts upon this feature.
Like you I will not rely upon it.

As I am curious, I will test it when I will install the new fileSystem introduced by 10.13

Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) vendredi 21 juillet 2017 14:13:52

Although those statements are technically contradictory… :wink:

If you pass a path beginning with a “:”, then yes, like a POSIX path not beginning with a “/”, it’s treated as a relative path, relative to the host’s current working directory. So, for example:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
current application's NSFileManager's defaultManager()'s changeCurrentDirectoryPath:"/Applications/Utilities"
set x to ":Script Editor.app"
x as alias
--> alias "Macintosh HD:Applications:Utilities:Script Editor.app:"

Which gives exactly the same result in any host.

But curiously, if the string is just “:” and nothing else (except more colons), it always seems to return the startup disk, regardless of the current directory.

And using multiple colons seems a bit odd these days too:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
current application's NSFileManager's defaultManager()'s changeCurrentDirectoryPath:"/Applications/Utilities"
set x to "::Script Editor.app"
x as alias --> alias "Macintosh HD:Applications:Utilities:Script Editor.app:"
set x to ":::Script Editor.app"
x as alias --> Error: File :::Script Editor.app wasn’t found

Edited to add missing “not”.

I did try to hedge my bets by saying “similar to”. :wink:

To come back with the trailing colons. I would rather use ‘…’ like it should be used:

set filePath to path to me

dirname(filePath)

on dirname(thePath)
	set thePath to thePath as string
	if thePath does not end with ":" then set thePath to thePath & ":"
	set dirname to (thePath & "..") as alias
	return dirname as string
end dirname