Help - Search - Members - Calendar
Full Version: AppleScript POSIX path
InsanelyMac Forum > Apple World > Mac Programming and Development
~pcwiz
Hi,

I am using AppleScript with POSIX paths and I am having trouble here. So say if I did this:

set theFile to choose file with prompt "Choose a file" without invisibles

The variable "theFile" would be something like this when I choose the file:

HD:Kexts:mykext.kext

So then I use POSIX to change the colons into slashes:

set theFilePOSIX to POSIX path of theFile

And the value of theFilePOSIX would be like:

HD/Kexts/mykext.kext/

The problem is that POSIX puts a slash at the end of mykext.kext, so it gets messed up, any way to remove this slash?
Airr
Here's one way:

CODE
set theFile to POSIX path of (choose file with prompt "Choose a file" without invisibles)
set theLength to (length of theFile) - 1
set theFile to characters 1 thru theLength of theFile as string


AIR.
~pcwiz
Thanks, but the problem with that method and the other one I tried is, strangely POSIX puts an extra slash on some kexts, but not for others, so sometimes it works for some kexts and for others it doesn't. I found the perfect solution though.

CODE
tell application "System Events" to set newVariable to POSIX path of oldVariable


Works fantastic.
Airr
QUOTE(~pcwiz @ May 16 2008, 04:12 PM) *
CODE
tell application "System Events" to set newVariable to POSIX path of oldVariable


Nice one!

Thanks for the tip!

AIR.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.