Preventing TM disk being ejected by a Apple Script that ejects disks

Preventing Time Machine ™ disk being ejected by a Apple Script that ejects disks?

I have an apple script to eject all network disks, but not any of the internal partitions I have.

Problem is that if TM is running when the script runs it also ejects the TM disk (this is on a remote server). This should not be so.

Below the script I use:

set exceptionsList to {"MobileBackups", "HD1", "HD2", "HD3", "HD4", "EFI", "Time Machine Backups"}
tell application "Finder"
	set diskList to the disks
	repeat with mountedDisk in diskList
		if name of mountedDisk is not in exceptionsList then
			eject mountedDisk
		end if
	end repeat
end tell

As you can see I have tried to use different names (MobileBackups", “HD1”, “EFI”, “Time Machine Backups”) for the TM disk to no avail.

Here is what I see for the TM disk if I run Disk Utility in Terminal, hence the names above.

/dev/disk5 (disk image):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme +450.0 GB disk5
1: EFI EFI 209.7 MB disk5s1
2: Apple_HFS Time Machine Backups 449.7 GB disk5s2

My question is how to prevent the TM disk from being ejected?

Thanks.

Hi,

while TM is running there are two shared volumes, Time Machine Backups and the enclosing volume (below named as VolumeOfTimeMachineBackups)

You can filter all shared volumes with System Events, on a local volume the server property is missing value.

tell application "System Events"
	set networkVolumes to name of disks whose name is not "Time Machine Backups" and name is not "VolumeOfTimeMachineBackups" and server is not missing value
end tell
tell application "Finder"
	repeat with aVolume in networkVolumes
		eject disk aVolume
	end repeat
end tell

Thanks. Does not work though. It still ejects the TM disk.

https://ibb.co/YDBtPzt

I tested the script.

On my machine it filters the TM volume reliably in the System Events line. Does the volume name contains special whitespace characters?

as I said this is what I see in Terminal

/dev/disk5 (disk image):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme +450.0 GB disk5
1: EFI EFI 209.7 MB disk5s1
2: Apple_HFS Time Machine Backups 449.7 GB disk5s2

Should I look somewhere else to see the name it might use?

I’m a bit confused because the name Time Machine Backups is predefined in the framework.

The check

name of disks whose name is not "Time Machine Backups"

must exclude the volume reliably.

Morning Stefan,

Could it have to do with the EFI Boot also being loaded? just a wild guess on my site.

I also tried:

tell application "System Events"
	set networkVolumes to name of disks whose name is not "Time Machine Backups" and name is not "VolumeOfTimeMachineBackups" and server is not missing value
end tell
tell application "Finder"
	repeat with aVolume in networkVolumes
		eject disk aVolume
	end repeat
end tell

But no succes.

I don’t think so. Does the EFI Boot volume appear in the disk list of System Events?

It may help Stefan to post what is returned by :

tell application "System Events"
	set networkVolumes to name of disks whose server is not missing value
end tell
tell application "Finder"
	set volNames to name of the disks
end tell

This way he would know the real names available and see if there is a difference between what is returned by Finder and System Events.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 27 janvier 2019 09:46:42

as posted above it shows in Terminal.

Returns: {}

Returns: {“.truecrypt_aux_mnt1”, “4916E083-E6669B1-4569871-B13C-820E20CE96DF”, “Data”, “DiskImage”, “MobileBackups”, “OS10.12”, “OS10.11”, “home”, “net”}

The Terminal output is irrelevant If you are getting the disks with Finder or System Events.

Anybody has an idea as to how to solve this?

What’s the name you gave to your TM disk?
Use that name in your exception list.

If that doesn’t work rename your TM disk to another name. And try again. The solution shouldn’t be hard to get. I guess you mess around with wild theories when the solution is at hand.
Don’t… Simply don’t use the Terminal. Why complicating things? Apart shell script you don’t need the Terminal. Here we code in Applescript dude! :lol:

I tried all you suggested and it is still ejecting the TM disk.

FYI I only posted the Terminal info as information in the hope it help to solve the problem.

So why does it keep ejecting the TM disk? Is it because it is on a server in the network?

Same here. According to System Events’s dictionary, the ‘server’ property only applies to AFP volumes, so if you’re using something else, all your disks’ ‘server’ values will be ‘missing value’. To filter for the names of non-local volumes, use:

tell application "System Events"
	set networkVolumes to name of disks whose local volume is false
end tell

You could also try using ‘displayed name’ instead of ‘name’ to see if that produces anything more recognisable as your TM volume name.

If the returned list doesn’t contain a name you can easily associate with your TM disk, you should try working through it one name at a time, explicitly telling the Finder to eject the disk of that name and making a note of which name(s) cause the TM disk to be ejected. Hopefully that’ll get you a little closer to a solution.

Thanks Nigel will give it a goo, helpful.

Everyone here gave you useful info (I don’t mind my bit of info although it’s still a hint)
If your ideas aren’t clear or complete nobody can please you. Nothing is obvious.

Hi Joy, not sure how to interpet your comments. would you like me to say thank you to all? Hereby done.