Once again I am pulling my hair out with path specifications in Applescript. I have written a script that need to load a file from a managed share (i.e. mounted via OD work group manager). The problem is that for reasons I don’t understand, the share gets mounted on occasion with a ‘-1’ appended to the share name. Therefore when my script tries to access /Volumes/Myshare/something, an error results because the path is /Volumes/Myshare-1/something. I figured the solution should be to simply test for that and set the appropriate path.
set mounted to POSIX path of "/Volumes/Myshare"
tell application "Finder"
if exists mounted then
set myshare to "/Volumes/Myshare"
else
set myshare to "/Volumes/Myshare-1"
end if
end tell
Whether the mount is ‘Myshare’ or ‘Myshare-1’ the ‘if’ always fails. I am guessing I am not specifying the path correctly thus the reason it is always false. Can someone help with the syntax of this? Thanks.
The problem is that your statement
set mounted to POSIX path of "/Volumes/Myshare"
Is setting mounted to a POSIX path which the finder doesn’t know how to deal with, so try something like this instead
set mounted to "/Volumes/Myshare"
tell application "Finder"
try
POSIX file mounted as alias
set myshare to "/Volumes/Myshare"
on error
set myshare to "/Volumes/Myshare-1"
end try
end tell
To address the larger issue though with the MyShare-1 assuming that you have ruled out the possibility of another filesystem being mounted with the same name it would appear that the drive is not unmounting cleanly and thus the mount point not being deleted. This would cause a new mount point (-1) to be created next time the volume is mounted.
Thanks for the reply. That seems to work.
What exactly does the ‘POSIIX file …’ do? That is a new command to me.
As to the reason for the extra mount point I have a suspicion it is the unclean unmount as you suggested. However, we have not yet converted our server to Leopard and I know there were many bugs introduced by 10.4.11 and then Apple withdrew ew just have to suffer with it until we can upgrade.
I typed a little too soon. I guess it is not quite that simple. Apparently when this condition exists, both mounts are present. However, the user can only access the ‘-1’ mount but both are there as far as Finder is concerned. The try is apparently never failing but when Applescript tries to access files on that share, it gets a ‘does not exist’ error. There seems to be an inconsistency here. If it can see the mount, why can’t it access file on it?
Problem is that technically it exists to the system, but because it’s a shadow mount you can’t do anything with it. Because I can’t really replicate your scenario at the moment try doing something like this
set mounted to "/Volumes/Myshare"
try
do shell script "ls " & mounted
set myshare to "/Volumes/Myshare"
on error
set myshare to "/Volumes/Myshare-1"
end try
If that still doesn’t catch it (ls might just return “”) then basically try to perform a action that IS failing as your test on a small scale in the script. From the result of that you know which mount to use for your actual operations.
Thanks for the reply. I was going to do that but I wasn’t sure how to ‘try’ with a ‘tell’ or even if I can. That is why I went down this other road. Essentially I am trying to load a script thus:
set ProgressBar to load script ("/Volumes/Myshare/AIM Apps/AppleScriptExtras/ProgressBar/BP Progress Bar Controller.scpt" as POSIX file)
tell ProgressBar to initialize("Address Book Updater")
.
.
.
end tell
The error occurs on the ‘tell’ not the ‘set’ which is where I’m stuck.
With a little more testing I think I understand the problem but not how to fix it. The problem is a little different then I thought. I was not looking at the error closely enough and the problem is not where I thought it was. In that script, there is a ‘launch’ of an application that is in the same folder as the loaded script. The loaded script is where the error occurs. So I tried to pass the path, as determined by the initial script to the loaded script. Unfortunately, apparently the path to an application cannot be passed as an argument, When I compile the loaded script, it does not ask where the application is and thus gets errors on commands to that application. Is there any way I can get this to work? Note, even putting a try in the loaded script will not work for the same reason. Thanks.