As an Applescript beginner, I am trying to write a script that opens shares on different servers for doing some file copying. The “open location” works fine until I add the specific share to the string. I get no error but the share is not mounted. The following works but prompts for the specific share:
set quote to """
set server_name to "afp://userid:password@10.0.1.131"
tell application "Finder"
open location quote & server_name & quote
end tell
The following does not prompt, does not mount and does not produce any error:
set quote to """
set server_name to "afp://userid:password@10.0.1.131"
tell application "Finder"
open location quote & server_name & "/My Share" & quote
end tell
Can someone please tell me what I’m doing wrong? TIA.
You don’t need the Finder for this task, since “open location” is part of Standard Additions. I think your problem is with the “quote” stuff. This works fine for me:
open location "afp://user:pass@192.168.200.1"
--> prompts for a volume to mount
open location "afp://user:pass@192.168.200.1/yoohoo"
--> doesn't prompt; mounts volume "yoohoo" from computer "192.168.200.1"
I didn’t post the entire script to avoid confusion but that may have caused some instead. It is inside a ‘tell’ because I use ‘exists’ to determine if the share is already mounted. If it is not then I issue the ‘open location’ and proceed with other things in ‘Finder’. I did try it without ‘quote’ but got the same result.
If there is a way to determine if the share is mounted without using ‘Finder’ then I can move all that outside the ‘tell’. I don’t know how to do it any other way but I somehow doubt having the ‘open’ inside the ‘tell’ is my problem.
P.S. Note that there is a space in the share name and all the examples I found doing this did not have any spaces. Although it shouldn’t be a problem I point that out just in case.
You still don’t need the quotes in the string you build.
The only purpose of the quote marks is to identify a string in AppleScript. The strings are not passed to the ‘open location’ command.
So when you:
open location "afp://user:password@192.168.0.1"
‘open location’ is passed the string afp://user:password@192.168.0.2
In your cases where you add the quotes:
open location quote & server_name & "/My Share" & quote
the ‘open location’ command is actually being passed a list consisting of ", afp://user:password@192.168.0.2, /My Share, and "
Eliminating the leading and trailing quote references would result in afp://user:password@192.168.0.2 and /My Share. Just to be safe you could coerce it to a string before passing it to open location:
open location (server_name & "/My Share" as string)