Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nicoisconfusion

macrumors newbie
Original poster
Sep 27, 2011
15
0
Hi guys i have a script finished but having trouble with looping something.

The script needs to mount an external hard drive
wait until a process is no longer running then unmount the disk

this is what i have so far using so far.


Code:
set myVolumeLabel to "disk1s2"

on ApplicationIsRunning(BreakTime)
	tell application "System Events" to set appNameIsRunning to exists (processes where name is BreakTime)
	return appNameIsRunning
end ApplicationIsRunning


tell application "Finder"
	set diskDev to do shell script "diskutil list | grep \"" & myVolumeLabel & "\" | grep -o 'disk[0-9]*' "
	if not (disk myVolumeLabel exists) then
		do shell script "diskutil mountDisk " & diskDev
	end if
end tell


if ApplicationIsRunning("BreakTime") then
	delay 5
	
else
	
	tell application "Finder"
		eject disk "10.5 Time Machine"
	end tell
end if
end

i just don't know how to make the script keep going until the process has ended. Once it has ended i want it to unmount
 
i got it sorted in the end with this

Code:
-- settings variables for the script
set myVolumeLabel to "disk2s2"

on ApplicationIsRunning(BreakTime)
tell application "System Events" to set appNameIsRunning to exists (processes where name is ChronoSync)
return appNameIsRunning
end ApplicationIsRunning

-- Telling the OS to mount the drive
tell application "Finder"
set diskDev to do shell script "diskutil list | grep \"" & myVolumeLabel & "\" | grep -o 'disk[0-9]*' "
if not (disk myVolumeLabel exists) then
do shell script "diskutil mountDisk " & diskDev
end if
end tell

-- Checking if the Process is running and repeating until it is closed 
if ApplicationIsRunning("BreakTime") then
repeat until ApplicationIsRunning("ChronoSync") = false
delay 10
end repeat
end if

-- ejecting the mounted disk
tell application "Finder"
eject disk "Backup"
end tell
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.