Mounting and unmounting SMB share's

Hi guys, is it possible to use a script to mount an SMB share, then copy a file to it?

Something like this may get you started.

set MyFile to choose file with prompt "Which file do you want to copy?"
tell application "Finder"
	try
		set TheServer to mount volume "smb://192.168.0.248/macraid"
	end try
	move file MyFile to TheServer
end tell

Thats what i needed, altho i have afew questions…

heres my scripts as it stands


set MyFile to "/Users/Shared/SystemProfiles/ibook.profile.txt"
tell application "Finder"
	try
		set TheServer to mount volume "smb://194.0.0.1/Share/"
	end try
	move file MyFile to TheServer
end tell

the file ibook.profile.txt is an output of the system_profiler command that has been saved by another script to that location.


Do shell script "system_profiler > /Users/Shared/SystemProfiler/ibook.profile.txt"

What i would like to do is take the mac’s computer name, in this case “ibook” and store it as a string and input it into both the scripts when it asks for the file;


/Users/Shared/SystemProfiles/"ComputerNameAsString".profile.txt

Cheers

Not sure and can’t check this but I think the startup disk is first listed in list disks. So you may be able to do it like this.

set MyMountedDisks to list disks
set MyMacsName to item 1 of (list disks)

Thanks for the reply but i think you have misunderstood what i would like to do!

I would like the machine name of the computer that is displayed on the network for example.

Is there a way of taking this string from the Sharing panel in system preferences and/or and other locations its stored?

From what i can tell from your reply that you give me the name of the mounted volume (HDD, EXT HDD, Network Drive etc).

Cheers again

hi dg,

this looks like a good way:


set normalCommand to do shell script "grep -A1 'ComputerName<' /Library/Preferences/SystemConfiguration/preferences.plist | grep -v key | sed s/\"[[:blank:]]*<\\/*string>\"//g"
display dialog normalCommand

which i got from here:

http://forums.macosxhints.com/archive/index.php/t-9792.html

there are other ideas also, but this one seems the best.

Thanks for the reply, ive used another command that was on that link for the script im using,


set hostname to do shell script "hostname -s"

Now that i have the computers name in the variable, how do i output it as a string so i can use it as a file name?

cheers again

hi dg,


set hostname to do shell script "hostname -s"

be aware that this is NOT the hostname, but rather the RENDEVOUS name, which could cause you problems down the line (especially bad if you are trying to make a script for use on multiple machines).

having said that:

Do shell script "/usr/sbin/system_profiler > /Users/Shared/SystemProfiler/" & quoted form of hostname & ".profile.txt"

EDITED: to add "& quoted form of " just in case there is a space in the name. with your Rendevous method there won’t be, but with my version it is possible. also, gave full path to ‘system_profiler’ for security reasons. --w

Thanks, that works a treat!!

One last little thing to fully automate this script, i mount a share to copy the file to once its saved on the local machine.
Is there anyway of entering the authentication details into the script?

This is what i have so far;


mount volume "smb://194.0.0.1/Share/"

Also, is there an unmount command?

Thanks again

Just figured it out how to unmount;


do shell script "umount -A"

still stuck on adding authentication to the script when mounting the server!!


tell application "finder" to
mount volume "smb://username:password@192.0.0.1/share"
end tell

Sorted =]