Davidavid
Aktives Mitglied
        Thread Starter
    
				
					
						- Registriert
- 07.08.2004
- Beiträge
- 677
- Reaktionspunkte
- 49
Ich habe mir mit Hilfe von ChatGPT zwei AppleScripte gebaut, mit dem ich per Tastaturkurzbefehl gemountete Volumes auf einen Schlag auswerfen kann, ohne die Maus zu bedienen. 
A möchte 1 Volume auswerfen (und fragt ggf. nach, welches).
B versucht alles Volumes auf einmal auszuwerfen.
Viel Spaß!
A: Ein Volume auswerfen:
	
	
	
		
B: Alle Volumes auswerfen:
	
	
	
		
	
		
			
		
		
	
				
			A möchte 1 Volume auswerfen (und fragt ggf. nach, welches).
B versucht alles Volumes auf einmal auszuwerfen.
Viel Spaß!
A: Ein Volume auswerfen:
		AppleScript:
	
	on playSuccess() -- Zupfen
    do shell script "afplay '/System/Library/Sounds/Purr.aiff' </dev/null >/dev/null 2>&1 &"
end playSuccess
on playError() -- Heldin
    do shell script "afplay '/System/Library/Sounds/Hero.aiff' </dev/null >/dev/null 2>&1 &"
end playError
tell application "Finder"
    set ejectables to every disk whose ejectable is true
    set n to count of ejectables
    
    if n = 0 then
        my playError()
        display notification "Keine externen Volumes gemountet" with title "Auswerfen"
        return
        
    else if n = 1 then
        set d to item 1 of ejectables
        set dn to (name of d as text)
        set ok to false
        try
            eject d
            set ok to true
        end try
        if ok then
            my playSuccess()
            display notification "Volume \"" & dn & "\" ausgeworfen" with title "Auswerfen"
        else
            my playError()
            display notification "Konnte \"" & dn & "\" nicht auswerfen" with title "Auswerfen"
        end if
        return
        
    else
        set namesList to {}
        repeat with d in ejectables
            set end of namesList to (name of d as text)
        end repeat
        
        activate
        set pick to choose from list namesList with prompt "Welches Volume auswerfen?" default items {item 1 of namesList} without multiple selections allowed
        if pick is false then return
        set chosenName to item 1 of pick
        
        set ok to false
        repeat with d in ejectables
            if (name of d as text) is equal to chosenName then
                try
                    eject d
                    set ok to true
                end try
                exit repeat
            end if
        end repeat
        
        if ok then
            my playSuccess()
            display notification "Volume \"" & chosenName & "\" ausgeworfen" with title "Auswerfen"
        else
            my playError()
            display notification "Konnte \"" & chosenName & "\" nicht auswerfen" with title "Auswerfen"
        end if
    end if
end tellB: Alle Volumes auswerfen:
		AppleScript:
	
	-- Sounds
on playSound(p)
    do shell script "afplay " & quoted form of p & " </dev/null >/dev/null 2>&1 &"
end playSound
on playPurr()
    my playSound("/System/Library/Sounds/Purr.aiff")
end playPurr
on playSosumi()
    my playSound("/System/Library/Sounds/Sosumi.aiff")
end playSosumi
on playBlow()
    my playSound("/System/Library/Sounds/Blow.aiff")
end playBlow
set perBeatDelay to 0.2
set finaleDelay to 0.25
-- Hauptlogik
tell application "Finder"
    set ejectables to every disk whose ejectable is true
    set n to count of ejectables
end tell
if n = 0 then
    my playBlow()
    display notification "Keine externen Volumes gemountet" with title "Alle auswerfen"
    return
end if
set okNames to {}
set failNames to {}
repeat with d in ejectables
    tell application "Finder" to set dn to (name of d as text)
    set did to false
    try
        tell application "Finder"
            eject d
            delay 0.3
            set stillThere to true
            try
                set stillThere to (exists d)
            on error
                set stillThere to false
            end try
        end tell
        if stillThere is false then set did to true
    on error
        set did to false
    end try
    
    if did then
        set end of okNames to dn
        my playPurr()
        delay perBeatDelay
    else
        set end of failNames to dn
        my playSosumi()
    end if
end repeat
if (count of failNames) = 0 then
    delay finaleDelay
    my playBlow()
    display notification "Alle (" & (count of okNames) & ") ausgeworfen: " & (okNames as text) with title "Alle auswerfen"
else
    set msg to ""
    if (count of okNames) > 0 then set msg to "Ausgeworfen: " & (okNames as text)
    if (count of failNames) > 0 then
        if msg ≠ "" then set msg to msg & " • "
        set msg to msg & "Fehlgeschlagen: " & (failNames as text)
    end if
    display notification msg with title "Alle auswerfen"
end if 
 
		 
 
		 
 
		