Rename USB Drive and create folder of the same name

I am conducting a reseach project for my masters degree in music technology.

Each of my students will be getting a flash drive with materials to use at home. Each week they come and plug their drive into my powerbook and it updates a couple of folders and then ejects the disk…

I have all the scripting done for the above.
I am try to cut down on the work of nameing the drive to the students name, then creating a folder of the same name, then transfering the the files on to the disk…

I am look for direction in wrting a scipt that when insert a drive labeled “UNTITLED” and run the script. a prompt will ask me to enter a name. Then it will rename the disk to that name and then create a folder of the same name on my computer… I can handle the copying over and such…

I apprecite any help you can give me.

thanks

Model: Powerbook 1.5
AppleScript: 1.107
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi,

the smartest solution is to install a launchd agent to watch the volumes folder

You need three scripts, because a script triggered by launchd doesn’t allow user interaction

script #1, saved somewhere as application, change the path in the make new folder line if necessary:

activate me
set theName to text returned of (display dialog "Enter name" default answer "" buttons {"Cancel", "OK"} default button 2)
tell application "Finder"
	set name of disk "UNTITLED" to theName
	make new folder at desktop with properties {name:theName} 
end tell

script #2, saved somewhere as compiled script (name doesn’t matter), adjust the path to the location of script #1

if "UNTITLED" is in (do shell script "ls /Volumes") then activate application "disk:path:to:script#1.app"

script #3, which installs the launchd agent.
Run it, choose script #2 and click “load” (it take some time, you get a message anyway)

property pListLabel : "WatchingVolumesFolder"

set LaunchAgentsFolder to make_new_folder(((path to home folder as Unicode text) & "Library:"), "LaunchAgents")
set LaunchScriptFolder to make_new_folder(path to scripts folder, "launchd")
set ScriptPOSIXpath to (POSIX path of LaunchScriptFolder & pListLabel)
set pListfile to ((LaunchAgentsFolder as Unicode text) & pListLabel & ".plist")
set scpt to choose file with prompt "Choose the AppleScript to be triggered by launchd"

set PLIST_File to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
	<key>Label</key>
	<string>" & pListLabel & "</string>
	<key>LowPriorityIO</key>
	<true/>
	<key>Program</key>
	<string>/usr/bin/osascript</string>
	<key>ProgramArguments</key>
	<array>
		<string>osascript</string>
		<string>" & ScriptPOSIXpath & ".scpt</string>
	</array>
	<key>ServiceDescription</key>
	<string>AppleScript directly when Volumes changes</string>
	<key>WatchPaths</key>
	<array>
		<string>/Volumes</string>
	</array>
</dict>
</plist>
"

set loadBut to button returned of (display dialog "Load or Unload launchd agent" buttons {"Cancel", "Unload", "Load"})
if loadBut is "Load" then
	write_to_file from PLIST_File into pListfile
	if the result is false then display dialog pListLabel & " couldn't be created" buttons {"Cancel"} default button 1
	do shell script "cp " & quoted form of POSIX path of scpt & space & quoted form of (ScriptPOSIXpath & ".scpt")
	launchctl("load", pListfile)
else
	launchctl("unload", pListfile)
end if

on launchctl(load, pListfile)
	try
		set launchctlCmd to "launchctl " & load & " -w " & quoted form of POSIX path of pListfile
		do shell script launchctlCmd
		if load is "unload" then do shell script "rm " & quoted form of POSIX path of pListfile
		display dialog quote & pListLabel & quote & " successfully " & load & "ed" buttons {"OK"} default button 1
	on error
		display dialog load & " failed" buttons {"Cancel"} default button 1 with icon stop
	end try
end launchctl

on write_to_file from |data| into target
	try
		set datastream to open for access file target with write permission
		write |data| to datastream as «class utf8»
		close access datastream
		return true
	on error
		try
			close access file target
		end try
		return false
	end try
end write_to_file

on make_new_folder(theFolder, fName)
	try
		return ((theFolder as Unicode text) & fName) as alias
	on error
		tell application "Finder" to return (make new folder at theFolder with properties {name:fName}) as alias
	end try
end make_new_folder

Your amazing…

I can’t thank you enough…

:smiley: