help with using posix paths

There is something wrong with the way I’m using posix paths, please help me figure it out…

I have a script to mount a volume from a server if necessary, and then launch a program. The program requires access to the shared volume while it’s launching.

if not (exists POSIX path of "/Volumes/Shared") then
tell application "Finder"
open location "afp://home/Shared"
end tell
tell application "Finder"
open POSIX path of "/Applications/MyProgram.app"
end tell
end if

The if test is not doing what I want: regardless of whether or not the volume is already mounted, nothing happens during the if statement. If i remove the “not”, then the server logs in normally and the server is mounted; but of course I still get an error if it’s mounted already. So it seems like the if not is always returning false, and the if is always returning true.

Maybe it’s not OK to use exists with a posix path? What’s the right way to do this test?

In the second statement, I get an error “Finder can’t get POSIX path of /Applications/MyProgram.app” instead of launching the app.

What am I doing wrong?

Hi.

I think the problem is that your if statement should be inside the Finder tell block.


tell application "Finder"
	if not (exists POSIX path of "/Volumes/Shared") then
		open location "afp://home/Shared"
		open POSIX path of "/Applications/MyProgram.app"
	end if
end tell

Actually, the POSIX path is used to convert Unicode text to Unix slashed file paths like this:

set a to POSIX path of "Pilate:Volumes:Shared:"

--> "/Volumes/Shared/"

or

set a to POSIX path of (path to shared documents as Unicode text)

--> "/Users/Shared/"

To go the other way, you need to use the POSIX file command:

set a to POSIX file  "/Users/Shared/"

Which then immediately compiles to this:

set a to file "Pilate:Users:Shared:"

--> file "Pilate:Users:Shared:"

Good luck,

Thanks Craig, the basic problem was my improper use of POSIX path instead of POSIX file. Also I directed the test statement to the Finder as capitalj suggested.

Is there any way to make the translation happen at runtime? With it happening at compile time, the script would break on a machine whose startup disk has a non-standard name.

Jason

Here’s the script:

tell application "Finder"
	if not (exists POSIX file "/Volumes/Shared") then
		open location "afp://home/Shared"
	end if
end tell
tell application "Finder"
	open POSIX file "/Applications/MyProgram.app"
end tell

I am not too sure, but my first guess would be to set the different files and apps to variables or properties:

tell application "Finder"
	set check_for to "/Volumes/Shared"
	set open_this to "/Applications/MyProgram.app"
	if not (exists POSIX file check_for) then
		open location "afp://home/Shared"
	end if
	open POSIX file open_this
end tell

My big question is whether it is even necessary to use Unix paths in the first place that then need to be converted. Is it not possible to simply use Mac paths in the first place?

That appears to work just fine, thanks again. I’d like to use Posix paths for this because every booted Mac filesystem starts with /, there’s no need to predict the actual name of the hard drive.

Jason

Final script:

tell application "Finder"
	set fmapp to "/Applications/MyProgram.app"
	set fmdir to "/Volumes/Shared"
	if not (exists POSIX file fmdir) then
		tell application "Finder"
			open location "afp://home/Shared"
		end tell
	end if
end tell
tell application "Finder"
	set n to 1
	repeat until n > 10
		if (exists POSIX file fmdir) then
			open POSIX file fmapp
			exit repeat
		end if
		delay 1
		set n to n + 1
	end repeat
end tell