Hasta ahora, he estado usando el siguiente AppleScript para expulsar todas las unidades externas a la vez convenientemente usando un atajo:
tell application "Finder"
eject (every disk)
end tell
Este script está almacenado /Library/Scripts
y he asignado un acceso directo para activarlo en FastScripts .
Pero hay un problema. Cuando tiene habilitadas las copias de seguridad de Time Machine , OS X monta un MobileBackups
volumen virtual /Volumes
para almacenar instantáneas locales . Este volumen se expulsará junto con todos los volúmenes físicos externos. Quiero evitar esto, ya que evitará que se realicen instantáneas locales (hasta que se vuelva a montar en el próximo inicio de sesión).
/Volumes/MobileBackups
en el AppleScript anterior?Este código AppleScript:
tell application "Finder"
set diskList to the disks
repeat with mountedDisk in diskList
if name of mountedDisk is not "MobileBackups" then
eject mountedDisk
end if
end repeat
end tell
expulsa todos los discos montados excepto cuando tiene el nombre MobileBackups
, es decir, /Volumes/MobileBackups
.
En su lugar, puede hacer lo siguiente:
tell application "Finder"
eject (every disk whose ejectable is true)
end tell
Si tiene discos particionados montados, mantenga presionada la tecla "Opción", ejecute su secuencia de comandos y luego suelte la tecla cuando haya terminado.
He modificado ligeramente esto para hacer exclusiones como un conjunto.
set exceptionsList to {"MobileBackups", "startup disk", "home", "net"}
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
Juntando las soluciones de Neil Ticktin y Dickster:
tell application "Finder"
set diskList to the disks whose ejectable is true
repeat with mountedDisk in diskList
set mountedDiskName to the name of mountedDisk
set skip to my skipDisk(mountedDiskName)
if skip is false then
eject mountedDisk
log "ejected " & mountedDiskName
else
log skip
end if
end repeat
end tell
-- skipDisk is either `false` or a string explaining what was skipped and why
on skipDisk(diskName)
set exceptionsList to {"TimeMachine", ".backup"}
if diskName is in exceptionsList then
return "skipped: \"" & diskName & "\" is in `exceptionsList`"
end if
repeat with exceptionDiskName in exceptionsList
if diskName contains exceptionDiskName then
return "skipped: \"" & diskName & "\" contains \"" & exceptionDiskName & "\""
end if
end repeat
return false
end skipDisk
Inspirado por la respuesta de Ady en esta publicación , aquí hay una versión más simple que funcionó para mí.
Filtre las copias de seguridad de TimeMachine ( Ejemplo: disco "2022-09-07-113224.backup" ) filtrando los volúmenes de propiedad raíz. Sin embargo, el enfoque de Zach es mucho más completo al verificar los nombres.
Esto es lo que funciona para mí.
tell application "Finder"
eject (every disk whose ejectable is true and local volume is true and format is not unknown format and owner is not "system")
end tell
Puede probar qué discos se expulsarán en el Editor de secuencias de comandos ejecutando
tell application "Finder"
every disk whose ejectable is true and local volume is true and format is not unknown format and owner is not "system"
end tell
Sam
zach joven