Silly question perhaps, but i can’t find it. I have a alias of a file and want the alias of the folder where the file is in.
parent, folder, container …? all don’t seem to work
Silly question perhaps, but i can’t find it. I have a alias of a file and want the alias of the folder where the file is in.
parent, folder, container …? all don’t seem to work
The fastest way by far is this: (which returns in “C” the alias to the container of myAlias)
set myAlias to choose file without invisibles
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set C to (((text items 1 thru -2 of (myAlias as text)) as text) & ":") as alias
set AppleScript's text item delimiters to tid
That works, perfect !! A great little script wich i didn’t use before. Many thanks!
Glad to help. I use it this way:
getContainer(choose file without invisibles) -- just a sample
to getContainer(myFile)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set C to (((text items 1 thru -2 of (myFile as text)) as text) & ":") as alias
set AppleScript's text item delimiters to tid
return C
end getContainer
If the input is a POSIX path, this does it (and obviously, we could combine these):
getContainerPX(POSIX path of (choose file without invisibles)) -- just a sample
to getContainerPX(myFile)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set C to (((text items 1 thru -2 of (myFile as text)) as text) & "/")
set AppleScript's text item delimiters to tid
return quoted form of C -- in case of internal spaces
end getContainerPX