Path of mounted volume varies

Hi, I’m a beginner with Applescript and need some assistance.

What I am trying to do is to modify a script that is part of a larger script that modifies a python script.
Problemmet is that the path to the .py script varies.
It is located on two different volumes and I can’t control what will be mounted on my Mac because of other corporate workflows that I can’t change.
What I am trying to do is get the path to change depending on the volume mounted, but due to lack of knowledge, I can’t get it to work.
Would be grateful if someone can give me some assistance.

Thanks

//Rikard

Here is my attempt at modification.

property dialog_timeout : 30 – set the amount of time before dialogs auto-answer.
property Vol2 : {“JobConf”}
property Vol22 : {“SecJobConf”}

set mountedDisks to paragraphs of (do shell script “/bin/ls /Volumes”)

if mountedDisks contains Vol22 then
set ServerVol to Vol22
else
if mountedDisks does not contain Vol22 then

	repeat with aDisk in Vol2
		
		if aDisk is not in mountedDisks then
			mount volume "smb://Servername/" & Vol2
			
		end if
	end repeat
	
	
	set x to "0"
	try
		do shell script "ls /Volumes/" & Vol2
	on error
		set x to "1"
	end try
	if x = "0" then set ServerVol to Vol2
end if

end if

set input to quoted form of POSIX path of “/Volumes/” & ServerVol & “/_Script/WorkScript.py”

– scriptcode

end

Hello

I don’t use servers but I’m not sure that the instructions defining properties are correct.
I would replace your :

property Vol2 : {“JobConf”}
property Vol22 : {“SecJobConf”}

by :

property Vol2 : “JobConf”
property Vol22 : “SecJobConf”

Yvan KOENIG (VALLAURIS, France) mercredi 24 septembre 2014 16:20:09

Hello,
you are right after removing the curly brackets it works. I didn’t see it, Thanks!

But still there is another problem, the script stops after

if mountedDisks contains Vol22 then
set ServerVol to Vol22

I though it should go to the main part of the script --scriptcode if Vol22 is mounted.

//Rikard

Hi,

there is some confusion about the single “SecJobConf” volume and the list of other volumes.
As there is only one other volume, the repeat loop is not needed


property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer.
property jobConfVolume : "JobConf"
property secVolume : "SecJobConf"

set serverVolume to missing value
set mountedDisks to paragraphs of (do shell script "/bin/ls /Volumes")

if mountedDisks contains secVolume then
	set serverVolume to secVolume
else
	try
		mount volume "smb://Servername/" & jobConfVolume
		set ServerVol to jobConfVolume
	end try
end if
if serverVolume is not missing value then
	set input to quoted form of "/Volumes/" & serverVolume & "/_Script/WorkScript.py"
else
	-- do error handling in case there is no volume available
end if

Hello,
thanks for your replay.

Before I posted the script I did some cleaning in the script for avoid confusion, my mistake.
There are three more volumes that needs to be mounted. But the path to those volumes are static.
So I think I need the repeat loop or is there a better solution?

//Rikard

if there are more volumes which one is supposed to be assigned to the serverVolume variable ?
This is a version with a repeat loop, the last successfully mounted volume is assigned to serverVolume if secVolume is not available


property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer.
property volumeList : {"JobConf"}
property secVolume : "SecJobConf"

set serverVolume to missing value
set mountedDisks to paragraphs of (do shell script "/bin/ls /Volumes")

if mountedDisks contains secVolume then
	set serverVolume to secVolume
else
	repeat with aDisk in volumeList
		try
			mount volume "smb://Servername/" & aDisk
			set ServerVol to aDisk
		end try
	end repeat
end if
if serverVolume is not missing value then
	set input to quoted form of ("/Volumes/" & serverVolume & "/_Script/WorkScript.py")
else
	-- do error handling in case there is no volume available
end if

The JobConf is other variable to serverVolume.

//Rikard

then change the try block to


		try
			mount volume "smb://Servername/" & aDisk
			if contents of aDisk is "JobConf" then set ServerVol to "JobConf"
		end try

Here another approach. It will actually work on mounted volumes instead of just looking for existing folder inside the /Volume folder. Looking for existence of a file or folder is no guarantee that the file system is actually mounted, nor does volumes have to be mounted inside the folder, they’re allowed to be mounted anywere in the system. It’s just Mac OS X’s default folder for all mount points. Also the script is using smbutil to lookup all available shares first. This way you can get rid of the ugly try block.

property jobConfVolume : {"JobConf"}
property secVolume : "SecJobConf"

tell application "System Events"
	set secVolPaths to path of every disk whose name is secVolume
end tell

if (count of secVolPaths) = 1 then
	set volumeNode to item 1 of HFSDiskPaths
else
	set availableShares to every paragraph of (do shell script "smbutil view //Servername | grep '\\bDisk\\b' | awk '{print $1}'")
	set volumeNode to missing value
	repeat with aDisk in jobConfVolume
		if jobConfVolume is in availableShares then
			set volumeNode to mount volume "smb://Servername/" & aDisk
			exit repeat
		end if
	end repeat
end if

if exists volumeNode then
	set input to quoted form of POSIX path of volumeNode
else
	--error handling
end if