dismounting a server when a program closes

If you save this as a stay open application, it might do what you need. When launched, it should open the file (assuming that that part of the code works). It will then check every 60 seconds to see if “Accelerated Reader® Student” has been quit. If so, it will (hopefully) unmount the server and quit itself.

on run
	tell application "Finder"
		mount volume "drive" on server "server" as user name "user" with password "password"
		open file "AR"
	end tell
end run

on idle
	tell application "Finder" to set exists_ to exists process "Accelerated Reader® Student"
	if exists_ is false then
		tell application "Finder" to eject disk "studat"
		tell me to quit
	end if
	return 60 -- seconds between checks
end idle

– Rob

on run
tell application “Finder”
mount volume “studat” on server “ML-STUDENT-SERV” as user name “admin” with password “mvwsd”
application “Finder”
activate
select file “AR”
open selection
end tell
end run

on idle
tell application “finder” to set exists process “Accelerated Reader® Student”
if exists_is false then
tell application “finder” to eject disk"studat"
tell me to quit
end if
renturn 60
end idle

thats what i have so far, but is saying

a end of line cannot go after the “Accelerated Reader® Student”

How about this?

on run
	tell application "Finder"
		mount volume "studat" on server "ML-STUDENT-SERV" as user name "admin" with password "mvwsd"
		activate
		select file "AR"
		open selection
	end tell
end run

on idle
	tell application "Finder" to set exists_ to exists process "Accelerated Reader® Student"
	if exists_ is false then
		tell application "Finder" to eject disk "studat"
		tell me to quit
	end if
	return 60
end idle

– Rob

Ok i am no getting an error anymore, the program is opening, but when it closes, it is still not kicking the server :-/
Any ideas?

Thank you so muc, youve been a life saver

Chris

If run run the following snippet, will it kick the server? If so, we might need to add a delay to the script.

tell application "Finder" to eject disk "studat"

Which version of Mac OS are you running? If Panther (10.3.x), you might be able to record the code to unmount the disk.

– Rob

It says disk “studat” does not reconise the command eject

edit:
I am running OS 9.2.2

i just did the command

tell application "Finder" to put away disk "studat"

and that did it, but it is still not putting it away when the program closes :-/

How are you running the script? If you are running it in Script Editor, the idle handler won’t execute. It must be saved as a stay open application and then launched like any other application.

– Rob

ummm i knew that yes…well ok i didnt, but I just went and did that, its sill not kicking it, i wish there was a cammand “when” but no there is not. Thank you again, youve been alot of help

Chris

Does the script quit after the “Accelerated Reader® Student” application is quit? It might take up to 60 seconds for this to occur. I just wonder if it’s only the ‘put away’ command that’s failing or if all of the code within the idle handler is failing.

– Rob

I can make a seperate script and the put away command works, so that makes me think that the put away works. I think its just not idling, because i had to go do something so i started it, let AR (acelerated reader) run for a lil bit, then closed it, then walked away for 10 min, came back server still there. is there another way to do it other than the if proccess AR exists, like on quit, or on close something like that?

What does this return with AR running and then when it is not running?

tell application "Finder" to exists process "Accelerated Reader® Student"

It should be true when AR is running and false when it isn’t running. If not, we’ve discovered the problem and it’s just a matter of determining the exact process name (it isn’t always the same as the application name). You can look at the results of the following snippet to try to determine the actual process name:

tell application "Finder" to name of processes

I’ll be leaving on a trip tomorrow (Thursday morning) and won’t get back into the swing of things until late Tuesday or early Wednesday. I won’t have Internet access and I had hoped to overcome this problem before leaving. It’s got to be something simple.

– Rob

OK i ran the first script with ar not open, it said false, ran it with ar open, said true. arg is it the idle process???

Chris

Based on your feedback, I don’t understand why the script fails. :?

– Rob

I know its been driving my crazyyy everythink seems to work except the idle, i did this, after the idle process, i tell it to open a picture, the picture opened right after AR opened, i think its skipping the idle process for some reason.

is there another way to do it other than idle?

someone help…please…

If you save this as a stay open application, does it work?

tell application "Finder"
	mount volume "studat" on server "ML-STUDENT-SERV" as user name "admin" with password "mvwsd"
	activate
	select file "AR"
	open selection
end tell

repeat
	do shell script "sleep 60" -- pauses script for 60 seconds - works only in OS X
	-- delay 60 -- use on pre-OS X machines
	tell application "Finder" to set exists_ to exists process "Accelerated Reader® Student"
	if exists_ is false then
		tell application "Finder" to put away disk "studat"
		tell me to quit
	end if
end repeat

– Rob

tell application "Finder"
	mount volume "studat" on server "ML-STUDENT-SERV" as user name "admin" with password "mvwsd"
	activate
	select file "AR"
	open selection
end tell

repeat
	tell application "Finder"
		"delay 60"
		tell application "Finder" to set exists_ to exists process "Accelerated Reader® Student"
		if exists_ is false then
			tell application "Finder" to put away disk "studat"
			tell me to quit
		end if
	end tell
end repeat

I got that to work except at the very very end it says;

Can’t get disk studat of application finder

its kicking the server, its doing everything else right!!! yay

Thank you very much

I’m sorry I’m just coming to this thread but looking at you script, the “delay 60” in quotes won’t do anything as a string and you’ve got al sorts of nested tells. I can’t test this but it seems to me this would work saved simply as an application (no explicit quit statement needed, it would just quit when the repeat loop exit conditions were met):

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]