Problem with moving files to networked volume

Hi All,

I just started developing a script(s) to install fonts across several machines on my network. My thought is this:
¢ Have a droplet on the client computers that moves fonts dropped on it to a folder called “Font Hub” on the server
¢ The droplet will trigger a script on the server via remote events that will distribute the fonts to designated computers on the network

Currently I’m working on the first part which is to mount the networked volume and move the fonts to the server. I’m not yet using it as a droplet just hard coding the source (fFont). The volume mounts fine but the shell script kicks an error basically stating the destination is not there. If the volume is already mounted then the script works fine. I have tried adding a delay and testing with “if exists” but no luck


set serverAddress to "BW-Server.local" -- ( IP address or servername.local )
set serverVolume to "Processed Images" -- Volume Name
set userName to "Admin"
set userPass to "password"
set fontHub to serverVolume & ":Font Hub:"
set fontHubPath to quoted form of POSIX path of fontHub
set fFont to alias "G5 Imaging HD:Users:marktorrance:Desktop:Install Fonts:"
set fFontPath to quoted form of POSIX path of fFont


--Mount the server
try
	mount volume "afp://" & serverAddress & "/" & serverVolume as user name userName with password userPass
on error
	display dialog "Unable to mount the volume \"" & serverVolume & "\" on the server at " & serverAddress & " with user name " & userName buttons {"OK"} default button {"OK"} with icon 2
end try
delay 15

-- Test for destination
tell application "Finder"
	if exists folder fontHub then
		display dialog "It's there"
		
		--Move fonts to server
		tell application "Finder"
			-- Get just files that are fonts
			set theFonts to (get files of entire contents of fFont whose kind contains "font")
			set nameFonts to {}
			
			-- Create list of the font names
			repeat with i in theFonts
				set end of nameFonts to name of contents of i
			end repeat
			
			-- Move the fonts to the Font Hub
			repeat with i in nameFonts
				set moveFont to (fFont & i as string)
				set moveFont to quoted form of POSIX path of moveFont
				do shell script "mv -f " & moveFont & "* " & fontHubPath
			end repeat
		end tell
	else
		display dialog "It's NOT there"
	end if
end tell

With the volume not mounted the first run returns “It’s There” from the “if exists” test but then errors on the shell script. On the second run, with the volume still mounted, it works fine.

Thanks,
Mark

Hi,

the problem is this line:

set fontHubPath to quoted form of POSIX path of fontHub

If the volume is not mounted, the result is “‘/Processed Images/Font Hub/’”, which is no valid path.
If the volume is mounted, you get the correct path “‘/Volumes/Processed Images/Font Hub/’”.
The delay is not needed. If no error occurs AppleScript waits until the volume is mounted.


set serverAddress to "BW-Server.local" -- ( IP address or servername.local )
set serverVolume to "Processed Images" -- Volume Name
set userName to "Admin"
set userPass to "password"

--Mount the server
if serverVolume is not in (do shell script "/bin/ls /Volumes") then
	try
		mount volume "afp://" & serverAddress & "/" & serverVolume as user name userName with password userPass
	on error
		display dialog "Unable to mount the volume \"" & serverVolume & "\" on the server at " & serverAddress & " with user name " & userName buttons {"OK"} default button {"OK"} with icon 2
		return
	end try
end if

if "Font Hub" is in (do shell script "/bin/ls /Volumes/" & quoted form of serverVolume) then
	set fontHubPath to quoted form of (POSIX path of serverVolume & ":Font Hub:")
	set fFont to ((path to desktop as text) & "Install Fonts:")
	set fFontPath to quoted form of POSIX path of fFont
	
	tell application "Finder"
		-- Get just files and their names that are fonts
		tell (files of entire contents of folder fFont whose kind contains "font") to set {nameFonts, theFonts} to {name of it, it}
		
		-- Move the fonts to the Font Hub
		repeat with i in nameFonts
			set moveFont to (fFont & i as string)
			set moveFont to quoted form of POSIX path of moveFont
			do shell script "mv -f " & moveFont & "* " & fontHubPath
		end repeat
	end tell
end if

Hi Stefan,

That makes perfect sense.

I tried your script but have a problem.

One the first run it seems to run properly. The volume is mounted and the files disappear from the source but don’t end up in the destination. They seem to disappear

I put two test fonts back in the source folder unmount the volume and run it again then I get an Applescript error
“ls: /Volumes/Processed Images: No such file or directory”

When I look in /Volumes i see a file called “Processed Images/Font Hub/” was left behind from the mounting process.

I made the following modifications and got it to work.


set serverAddress to "BW-Server.local" -- ( IP address or servername.local )
set serverVolume to "Processed Images" -- Volume Name
set userName to "Admin"
set userPass to "password"
set fFont to ((path to desktop as text) & "Install Fonts:")
set fFontPath to quoted form of POSIX path of fFont

--Mount the server
if serverVolume is not in (do shell script "/bin/ls /Volumes") then
	try
		mountVolume(serverAddress, serverVolume, userName, userPass)
	on error
		display dialog "Unable to mount the volume \"" & serverVolume & "\" on the server at " & serverAddress & " with user name " & userName buttons {"OK"} default button {"OK"} with icon 2
		return
	end try
end if

tell application "Finder"
	set fontHub to serverVolume & ":Font Hub:"
	if exists folder fontHub then --"Font Hub" is in (do shell script "/bin/ls /Volumes/" & quoted form of serverVolume) then
		set fontHubPath to quoted form of POSIX path of fontHub
		
		-- Get just files and their names that are fonts
		tell (files of entire contents of folder fFont whose kind contains "font") to set {nameFonts, theFonts} to {name of it, it}
		
		-- Move the fonts to the Font Hub
		repeat with i in nameFonts
			set moveFont to (fFont & i as string)
			set moveFont to quoted form of POSIX path of moveFont
			do shell script "mv -f " & moveFont & "* " & fontHubPath
		end repeat
		
	end if
end tell

on mountVolume(serverAddress, serverVolume, userName, userPass)
	mount volume "afp://" & serverAddress & "/" & serverVolume as user name userName with password userPass
end mountVolume

Do you see any major problems in my script? I made the mount volume handler in case I decide to include a try again button in the “failed to mount” dialog.

Thanks for you help,
Mark

my fault, the problem is, the whole path must be quoted


 if "Font Hub" is in (do shell script "/bin/ls " &  quoted form of ("/Volumes/" & serverVolume)) then

I still get the same issues.
First run:
Volume Mounts
Files leave the source folder but don’t make it to the destination.

I unmount the volume

Second Run:
Error
When I look in /Volumes i see a file called “Processed Images/Font Hub/” was left behind after the volume is unmounted.

Thanks,
Mark

I never use volume names containing space characters, they cause always problems :wink:
Change this line, too


.
if serverVolume is not in (do shell script "/bin/ls " & quoted form of ("/Volumes/" & serverVolume))
.

This errors “ls: /Volumes/Processed Images: No such file or directory” on the shell script to mount the server.



set serverAddress to "BW-Server.local" -- ( IP address or servername.local )
set serverVolume to "Processed Images" -- Volume Name
set userName to "Admin"
set userPass to "password"

--Mount the server
if serverVolume is not in (do shell script "/bin/ls " & quoted form of ("/Volumes/" & serverVolume)) then
	try
		mount volume "afp://" & serverAddress & "/" & serverVolume as user name userName with password userPass
	on error
		display dialog "Unable to mount the volume \"" & serverVolume & "\" on the server at " & serverAddress & " with user name " & userName buttons {"OK"} default button {"OK"} with icon 2
		return
	end try
end if

if "Font Hub" is in (do shell script "/bin/ls " & quoted form of ("/Volumes/" & serverVolume)) then
	set fontHubPath to quoted form of (POSIX path of serverVolume & ":Font Hub:")
	set fFont to ((path to desktop as text) & "Install Fonts:")
	set fFontPath to quoted form of POSIX path of fFont
	
	tell application "Finder"
		-- Get just files and their names that are fonts
		tell (files of entire contents of folder fFont whose kind contains "font") to set {nameFonts, theFonts} to {name of it, it}
		
		-- Move the fonts to the Font Hub
		repeat with i in nameFonts
			set moveFont to (fFont & i as string)
			set moveFont to quoted form of POSIX path of moveFont
			do shell script "mv -f " & moveFont & "* " & fontHubPath
		end repeat
	end tell
end if


This works:


set serverAddress to "BW-Server.local" -- ( IP address or servername.local )
set serverVolume to "Processed Images" -- Volume Name
set userName to "Admin"
set userPass to "password"


--Mount the server
try
	mount volume "afp://" & serverAddress & "/" & serverVolume as user name userName with password userPass
on error
	display dialog "Unable to mount the volume \"" & serverVolume & "\" on the server at " & serverAddress & " with user name " & userName buttons {"OK"} default button {"OK"} with icon 2
end try



-- Test for destination
if "Font Hub" is in (do shell script "/bin/ls " & quoted form of ("/Volumes/" & serverVolume)) then
	tell application "Finder"
		set fontHub to serverVolume & ":Font Hub:"
		if exists folder fontHub then
			
			set fontHubPath to quoted form of POSIX path of fontHub
			set fFont to alias "G5 Imaging HD:Users:marktorrance:Desktop:Install Fonts:"
			set fFontPath to quoted form of POSIX path of fFont
			
			--display dialog "It's there"
			
			--Move fonts to server
			tell application "Finder"
				-- Get just files that are fonts
				set theFonts to (get files of entire contents of fFont whose kind contains "font")
				set nameFonts to {}
				
				-- Create list of the font names
				repeat with i in theFonts
					set end of nameFonts to name of contents of i
				end repeat
				
				-- Move the fonts to the Font Hub
				repeat with i in nameFonts
					set moveFont to (fFont & i as string)
					set moveFont to quoted form of POSIX path of moveFont
					do shell script "mv -f " & moveFont & "* " & fontHubPath -- use shell script to avoid authentication
				end repeat
				
			end tell
		end if
	end tell
end if

Thanks,
Mark