Jump to content

AppleScript POSIX path


4 posts in this topic

Recommended Posts

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?

Link to comment
Share on other sites

Here's one way:

 

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.

Link to comment
Share on other sites

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.

 

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

 

Works fantastic.

Link to comment
Share on other sites

 Share

×
×
  • Create New...