Volumen von automount ausschliessen

Atalantia

Atalantia

Aktives Mitglied
Thread Starter
Dabei seit
26.11.2009
Beiträge
1.893
Reaktionspunkte
431
Nützlich gegen Tool Partitionen, die es ab und zu auf USB Sticks und sogar auf Festplatten hat. Wer die nicht gemounted haben will kann das mit diesem AppleScript verhindern.

Code:
on open var
    doIt(var)
end open
set var to choose folder multiple selections allowed yes
doIt(var)
on doIt(var)
    repeat with x in var
        tell application "System Events"
            set {kindInfo, nameInfo} to {kind of x, name of x}
        end tell
        if kindInfo ≠ "Volume" then
            display alert "Works with volumes only"
            return
        end if
        display dialog "Suspend automount for " & nameInfo & " ?" with icon 1 with title "Auto mount off."
        do shell script "echo " & ("UUID=" & (do shell script "diskutil info " & quoted form of POSIX path of x & " | grep UUID | awk '{print $3}'") & " none hfs rw,noauto") & " >> /etc/fstab" with administrator privileges
    end repeat
end doIt
 
  • Gefällt mir
Reaktionen: Schiffversenker
ich würde noch nameInfo kommentiert in die fstab schreiben.
 
  • Gefällt mir
Reaktionen: Atalantia
Ja besser. Wenn sich da mal 27 Volumes ansemmeln, weiss man noch um welche es sich handelt.
Code:
on open var
    doIt(var)
end open
set var to choose folder multiple selections allowed yes with prompt "Choose volume(s) to suspend."
doIt(var)
on doIt(var)
    repeat with x in var
        tell application "System Events"
            set {kindInfo, nameInfo} to {kind, name} of x
        end tell
        if kindInfo ≠ "Volume" then
            display alert "Works with volumes only."
            return
        end if
        display dialog "Suspend automount for " & nameInfo & " ?" with icon 1 with title "Auto mount off."
        do shell script "echo " & "'# '" & nameInfo & return & ("UUID=" & (do shell script "diskutil info " & quoted form of POSIX path of x & " | grep UUID | awk '{print $3}'") & " none hfs rw,noauto") & " >> /etc/fstab" with administrator privileges
    end repeat
end doIt
 
Update: Der Zeilenumbruch ist jetzt UNIX Konform.
Code:
on open var
    doIt(var)
end open
set var to choose folder multiple selections allowed yes with prompt "Choose volume(s) to suspend."
doIt(var)
on doIt(var)
    repeat with x in var
        tell application "System Events"
            set {kindInfo, nameInfo} to {kind, name} of x
        end tell
        if kindInfo ≠ "Volume" then
            display alert "Works with volumes only."
            return
        end if
        display dialog "Requires restart to take effect..." with icon 1 with title "Suspend automount for " & nameInfo
        do shell script "echo '#'" & nameInfo & "'
'" & ("UUID=" & (do shell script "diskutil info " & quoted form of POSIX path of x & " | grep UUID | awk '{print $3}'") & " none hfs rw,noauto") & " >> /etc/fstab" with administrator privileges
    end repeat
end doIt
 
Warum ist denn hier das Editieren ausgeschaltet? Na, ganz schlau.
 
ich habe meinen #2 auch schon gemeldet, weil ich irgendwas editieren wollte. interessiert nur leider keine alte sau. :noplan:

dein fstab-schreiben ist auch etwas unorthodox, mit dem verschachtelten do shell script.
Code:
do shell script "echo \"# " & nameInfo & "
UUID=$(diskutil info " & quoted form of POSIX path of x & " | grep 'UUID' | awk '{print $3}') none hfs rw,noauto\" >> /etc/fstab" with administrator privileges
 
  • Gefällt mir
Reaktionen: Atalantia
Update:
Code:
on open var
    try
        doIt(var as alias)
    on error number ernb
        if ernb = -128 then error number -128
        display alert "Works with only one volumes at the time." as critical
        return
    end try
end open
set var to choose from list (list disks) with prompt "Choose volume to suspend." with title "fstabExcludeVolume"
if var = false then error number -128
doIt(var as alias)

on doIt(var)
    tell application "System Events"
        set {kindInfo, nameInfo} to {kind, name} of var
    end tell
    if kindInfo ≠ "Volume" then
        display alert "Works with volumes only."
        return
    end if
    display dialog "Requires restart to take effect." with icon 1 with title "Suspend automount for " & nameInfo
    do shell script "echo \"# " & nameInfo & "
UUID=$(diskutil info " & quoted form of POSIX path of var & " | grep 'UUID' | awk '{print $3}') none hfs rw,noauto\" >> /etc/fstab" with administrator privileges
end doIt
 
  • Gefällt mir
Reaktionen: mausfang
normalerweise reicht ein "mount -a" hinterherzuwerfen, das spart das rebooten.
 
  • Gefällt mir
Reaktionen: mausfang
Zurück
Oben Unten