24/05/08
Fast AFP Mount 2.0

J'avais déjà grandement écrit ce script il y a près d'un an… cependant, quelques détails me chagrinaient, comme les appels à des display dialog pour sa phase de configuration, un côté bien plus usine à gaz que la version actuelle et d'autres détails… Aujourd'hui, j'avais besoin de quelque chose de ce genre mais qui puisse être rapidement configuré et déployé pour 1 à n volumes AFP ; aussi me suis je penché à nouveau sur le code de cet ancien script (dont je n'avais pas encore parlé ici) pour en faire une version 2.
En effet, sous Mac OS X 10.4 (aka Tiger), je n'ai jamais réussi à mettre des disques AFP en montage automatique dans les Préférences > Comptes > Ouverture avec mon petit réseau domestique. De même, l'utilisation de SharePoints AutoMounter ou encore la mise en œuvre de ce tutoriel : Automounting Sharepoints at Startup sont restées sans effet !
(* Fast AFP Mount.scpt HP <http://blogosx.jupiterii.com> updated May. 24, 2007 This script is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation *) on run set otid to text item delimiters growlRegister() --main variables set {host2mount, disk2mount} to {"", ""} set afp_identifiers to ";AUTH=NO%20USER%20AUTHENT" set appNAme to name of (info for (path to me)) set host2mount to StrReplace(".app", "", appNAme) --obtention du nom du dernier dossier set text item delimiters to {"/"} set liste to text items of host2mount set disk2mount to last item of liste set text item delimiters to otid if createMountPoint(disk2mount) then if (mountAFPVolume(afp_identifiers, host2mount, disk2mount)) then set notifName to (localized string "volume_mounted" from table "Localizable") set notifDesc to (disk2mount & return & host2mount) growlNotif(notifName, notifDesc, localized string "app_name" from table "Localizable") end if end if end run (* Functions : growl() [test if growl run or not] createMountPoint(disk2mount) [mkdir] mountAFPVolume(afp_identifiers, host2mount, disk2mount) growlRegister() growlNotif(notifName, notifDesc, appNAme) errorMessage(msg) StrReplace(find, replace, str) *) on growl() tell application "System Events" set isRunning to (count of (every process whose name is "GrowlHelperApp")) > 0 end tell return isRunning end growl on createMountPoint(disk2mount) set mount_flag to false set mkdir to "" repeat try do shell script "mkdir " & "/Volumes/" & disk2mount & "_afp" if (do shell script "ls /Volumes/" contains disk2mount) then exit repeat end if on error error_message set mkdir to error_message end try if (mkdir contains "File exists") then set mount_flag to true exit repeat end if end repeat if (mount_flag = false) then errorMessage(mkdir) return mount_flag end createMountPoint on mountAFPVolume(afp_identifiers, host2mount, disk2mount) set productVersion to do shell script "sw_vers -productVersion" set afp_location to "afp://" & afp_identifiers & "@" & host2mount & "/" & disk2mount log afp_location if productVersion < "10.5" then --nfsiod daemon repeat set myTop to do shell script "top -l 1" as string if ((myTop contains space & "nfsiod" & space) ¬ and (myTop contains space & "automount" & space)) then exit repeat end repeat end if try set cmd to "mount_afp " & quoted form of afp_location & " " & quoted form of "/Volumes/" & disk2mount & "_afp" do shell script cmd on error error_m return errorMessage(error_m) end try return true end mountAFPVolume on growlRegister() if growl() then set str_mounted to localized string "volume_mounted" from table "Localizable" set str_error to localized string "error" from table "Localizable" tell application "GrowlHelperApp" set the allNotificationsList to {str_mounted, str_error} set the enabledNotificationsList to {str_mounted, str_error} register as application ¬ "Fast AFP Mount" all notifications allNotificationsList default notifications enabledNotificationsList icon of application (name of (info for (path to me))) end tell end if end growlRegister on growlNotif(notifName, notifDesc, appNAme) if growl() then tell application "GrowlHelperApp" --Send a Notification… notify with name notifName title ¬ (notifName) description ¬ (notifDesc) application name appNAme icon of application (name of (info for (path to me))) end tell end if end growlNotif on errorMessage(msg) beep if (growl()) then set notifName to localized string "error" from table "Localizable" set notifDesc to msg set appNAme to localized string "app_name" from table "Localizable" growlNotif(notifName, notifDesc, appNAme) else display alert msg as warning end if return false end errorMessage on StrReplace(find, replace, str) set ditd to text item delimiters set res to missing value set text item delimiters to find repeat with tis in text items of str if res is missing value then set res to tis else set res to res & replace & tis end if end repeat set text item delimiters to ditd return res end StrReplace
Il suffit de dupliquer et de renommer l'application (progiciel AppleScript) pour que celle-ci sache quel serveur (ou adresse IP) utiliser et quel disque monter… ça a le mérite d'être assez simple, et de permettre de lancer 1 à n petites applications lors du boot de la machine… Le script utilise uniquement des notifications Growl seulement si Growl est installé, rendant Growl optionnel… si Growl n'est pas installé, les messages d'erreur éventuels seront gérés par un display alert, ce qui est moins agréable !
L'application est localisable, grâce à l'utilisation des Localizable.strings. Le script est clairement optimisé pour Mac OS 10.4, je ne l'ai pratiquement pas utilisé sous Leopard (Mac OS 10.5), et j'ignore même si il y serait d'une utilité quelconque.
L'application reste masquée et n'apparaît pas dans le Dock (tâche de fond), grâce à l'utilisation de LSUIElement dans Info.plist, c'est assez pratique, si par exemple on monte 3 (ou plus) volumes au démarrage :
<key>LSUIElement</key> <true/>
Icône venant du thème Oxygen.
Télécharger
Télécharger : Fast AFP Mount 2.0 RC1
Archive, ±88 Ko
MD5 (Fast AFP Mount.zip) = 75f82e16e9c3952d48e91f32f76db4a0
