I'm confused - I've been googling for an hour and have tried probably ten different forms of set posixDirectory to POSIX path of (parent of (path to aFile) as string)
but I can't seem to get it right.
I'm getting the full POSIX path (including the filename) by doing
set posixFilePath to POSIX path of aFile
Now, how do I get the POSIX path of just the directory?? I'm getting various errors depending on what I do... can't make alias.. can't get parent of alias...
I would think this should work but it's not...
set posixDirectory to POSIX path of ((parent of aFile))
There are couple of ways to do this if you already have the initial path.
From Posix path format
set thePath to "/Users/USERNAME/Documents/Test/selectedTextColour.css"
set textNumber1 to characters 1 thru -((offset of "/" in (reverse of items of thePath as string)) + 1) of thePath as string
or using shell
set thePath to "/Users/USERNAME/Documents/Test/selectedTextColour.css"
set parentPath to do shell script "dirname " & quoted form of thePath
Result: "/Users/USERNAME/Documents/Test"
From Posix file format
set thePath to "Macintosh HD:Users:USERNAME:Documents:Test:selectedTextColour.css"
set textNumber1 to characters 1 thru -((offset of ":" in (reverse of items of thePath as string)) + 1) of thePath as string
Result: "Macintosh HD:Users:USERNAME:Documents:Test"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With