POSIX file and POSIX path

G’day again,

I am storing some path information to be passed to another script but I cannot get what looks like a perfectly good path turned back into an alias or file reference.

In the app that stores the path I do this, though its not so cut and dried as the location of gPicturesFolder varies, and I’ve chomped out the error checking:


set gPicturesFolder to ((path to desktop folder as string) & "iMaginePictures") as alias
set storePathToPictures to path to temporary items
set storePathToPictures to ((storePathToPictures as string) & "PathFileName.txt")
set fileReferenceNum to (open for access storePathToPictures with write permission)
write (POSIX path of gPicturesFolder) to fileReferenceNum
close access fileReferenceNum

and I know that works, the file gets created and the desired path gets written.
In the script that reads the file I do the following.


set storePathToPictures to ((path to temporary items as string) & "PathFileName.txt") as alias
set fileRef to (open for access storePathToPictures without write permission)
set thePicLocation to (read fileRef)
close access fileRef
display dialog "Folder location is: " & thePicLocation
set thePicLocation to (thePicLocation as POSIX file)
display dialog "Folder location is: " & thePicLocation as string

When the first folder location dialog comes up the path looks dandy. But once I try and convert it and show it in the second dialog the string is: “: :”

I’ve even tried using the quoted form, I’ve also tried removing the last character “/” in desperation. Nothing works. Any help would be greatly appreciated.

Kevin

Sorted, javascript:emoticon(‘:D’)

When reading in the text file I have to read it in as Unicode text, for example


set thePicLocation to (read fileRef)

becomes


set thePicLocation to (read fileRef as Unicode text)

Kevin
javascript:emoticon(‘:D’)

Are you converting to posix paths only for the sake of storage in the file or does the script actually need a posix path?

I am using POSIX paths in other places in the calling script. But I could use the old Mac OS paths in this case. I am generally trying to make the switch over to posix paths wherever possible.

Would that make a difference in relation to having to read the file as Unicode text or not.

Kevin

I won’t pretend to understand all of the intricacies of the various types of text because I find it all very confusing. As far as I know, AppleScript OS X uses Unicode text for paths to overcome issues where a path might include a character that causes problems otherwise. If you don’t feel that this will be an issue, here’s a handler that will convert paths to plain text. If I’m not mistaken, the handler was written by Arthur Knapp.

set path_ to (choose folder) as text
set plain_ to AsText(path_)

on AsText(str)
	try --coerce Unicode or other text to styled string to plain text
		return (((str as string) as record)'s «class ktxt»)
	end try
	return str -- if plain text to begin with
end AsText

If you don’t want to use this then we need to figure out how to read the file as is. :stuck_out_tongue:

– Rob

Thanks for your thoughts Rob

I managed to read the file successfully as unicode text and the path was converted correctly to a POSIX file. Everything is now hunky dory especially the AS studio app that is now finished.