| « ND8 | D.O.I.T. » |
Applescript : automount
ou comment monter des volumes sans se fatiguer, avec contrôle d'erreurs, notifications growl et installation en login item. tout ce qu'il faut faire c'est le placer dans le dossier application (enregistré en appli)
Pour la licence, je remets pas le bloc, mais c'est bien entendu GPL v3
Code:
try | |
tell application "System Events" | |
get exists login item "automount" | |
if result is false then | |
make new login item at end of login items with properties | |
{path:"/Applications/automount.app", hidden:true, kind:"Application"} | |
end if | |
end tell | |
end try | |
| |
try | |
tell application "System Events" to set GrowlExists to exists | |
application process ("GrowlHelperApp" as string) | |
if (GrowlExists) then | |
tell application "GrowlHelperApp" | |
set the allNotificationsList to ¬ | |
{"Succes", "Echec", "Erreur"} | |
set the enabledNotificationsList to ¬ | |
{"Succes", "Echec", "Erreur"} | |
register as application ¬ | |
"Automount" all notifications allNotificationsList ¬ | |
default notifications enabledNotificationsList ¬ | |
icon of application "Disk Utility" | |
end tell | |
else | |
set growlURL to "http://growl.info/index.php" | |
display dialog "Ce script fonctionne (mieux) avec Growl installé sur | |
le système." & return & "Aller sur " & growlURL & " pour le | |
télécharger ?" with icon note buttons {"Oui", "Non"} default button | |
{"Oui"} | |
if button returned of result is "Oui" then | |
open location growlURL | |
end if | |
end if | |
end try | |
| |
try | |
set myVolumes to {¬ | |
"afp://login:pass@ip/folder/", ¬ | |
"smb://login:pass@ip/share_name/"} | |
end try | |
| |
tell application "Finder" | |
repeat with currentVolume in myVolumes | |
try | |
set AppleScript's text item delimiters to {"/"} | |
set myParts to text items of currentVolume | |
set myLength to the count of myParts | |
set myName to text item (myLength - 1) of myParts | |
end try | |
if not (exists the disk myName) then | |
try | |
mount volume currentVolume | |
on error errText number errNum | |
if errNum is -55 then | |
if (GrowlExists) then | |
tell application "GrowlHelperApp" | |
notify with name ¬ | |
"Echec" title ¬ | |
"Montage" description "Le volume '" & myName & ¬ | |
"' est déjà monté sur le bureau !" application name ¬ | |
"Automount" icon of application "Disk Utility" | |
end tell | |
else | |
display dialog "Le volume '" & myName & "' est déjà monté sur le | |
bureau !" with icon 2 | |
end if | |
else if errNum is -128 then | |
if (GrowlExists) then | |
tell application "GrowlHelperApp" | |
notify with name ¬ | |
"Echec" title ¬ | |
"Erreur de montage" description "Action annulée lors du | |
montage de '" & myName & ¬ | |
"' " application name ¬ | |
"Automount" icon of application "Disk Utility" | |
end tell | |
else | |
display dialog "Action annulée lors du montage de '" & myName & | |
"' " with icon 0 buttons {"OK"} default button {"OK"} | |
| |
end if | |
else | |
if (GrowlExists) then | |
tell application "GrowlHelperApp" | |
notify with name ¬ | |
"Echec" title "Erreur de montage n°" & errNum ¬ | |
description "Impossible de monter le volume '" & myName & "' " | |
& return & "--" & return & "Message système : " & return & errText ¬ | |
application name ¬ | |
"Automount" icon of application "Disk Utility" | |
end tell | |
else | |
display dialog "Impossible de monter le volume '" & myName & "' | |
" & return & "--" & return & "Message système : " & return & errText | |
with icon 0 buttons {"OK"} default button {"OK"} | |
end if | |
end if | |
end try | |
if (GrowlExists) then | |
tell application "GrowlHelperApp" | |
notify with name ¬ | |
"Succes" title ¬ | |
"Volume monté" description "Le volume '" & myName & ¬ | |
"' a bien été monté sur le bureau" application name ¬ | |
"Automount" icon of file "file:///Volumes/" & myName | |
| |
end tell | |
end if | |
end if | |
end repeat | |
end tell | |
| |
try | |
tell application "automount" to quit | |
on error | |
if (GrowlExists) then | |
tell application "GrowlHelperApp" | |
notify with name ¬ | |
"Erreur" title ¬ | |
"Erreur lors de la sortie" description ¬ | |
"Impossible de quitter Automount" application name ¬ | |
"Automount" icon of application "Disk Utility" | |
end tell | |
else | |
display dialog "Impossible de quitter Automount" with icon 0 buttons | |
{"OK"} default button {"OK"} | |
end if | |
end try |
Adresse de trackback pour cet article
Trackback URL (right click and copy shortcut/link location)