• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Wir haben den Frühjahrsputz beendet, Ihr auch? Welches Foto zu dem Thema hat Euch dann am Besten gefallen? Hier geht es lang zur Abstimmung --> Klick

AFP-Share mounten - ein schönes kleines Script

SirFledermaus

Braeburn
Registriert
17.09.09
Beiträge
43
Hallo Leute,

ich habe mir mal vor einiger Zeit ein Apple-Script gebaut, was mir zu Hause mein AFP-Share auf meiner NAS verbindet, wenn ich in meinem WLAN bin und die NAS erreichbar ist. Ich hatte mal ein MacBook-Air mit wenig SSD-Kapazität und war es leid, immer manuell mein Share zu verbinden. Also habe ich dieses Script geschrieben, als .app gespeichert und mit "iBackground Scripts" unsichtbar gemacht. Dazu das Ding mit dem SleepWatcher aufrufen und als Startprogramm für meinen User hinterlegt. Klappt Super!

Ich hoffe, es kann wer gebrauchen oder zumindest daraus andere Sachen ableiten. :)


Hier das Script und dazu nochmal hier.

Code:
[B]set[/B] [COLOR=#4f8f00]serv[/COLOR] [B]to[/B] "iServer"
[B]set[/B] [COLOR=#4f8f00]SSID[/COLOR] [B]to[/B] "Mikrowelle"
[B]set[/B] [COLOR=#4f8f00]aSSID[/COLOR] [B]to[/B] 1
[B]set[/B] [COLOR=#4f8f00]vol[/COLOR] [B]to[/B] {"Storage"}
[COLOR=#4F8F00][COLOR=#000000][B]set[/B] [/COLOR]firstMount[COLOR=#000000] [B]to[/B] [/COLOR][COLOR=#5d3292]true[/COLOR][/COLOR]


[COLOR=#4F8F00][COLOR=#000000][B]if[/B] [B]my[/B] [/COLOR]checkServer[COLOR=#000000]([/COLOR]serv[COLOR=#000000]) [B]and[/B] [/COLOR]checkWiFi[COLOR=#000000]([/COLOR]SSID[COLOR=#000000]) [B]then[/B][/COLOR][/COLOR]
	[B]if[/B] [COLOR=#4f8f00]vol[/COLOR] [B]is not[/B] [B]in[/B] ([COLOR=#012fbe][B]list disks[/B][/COLOR]) [B]then[/B]
[COLOR=#5E6161][COLOR=#000000]		[/COLOR]-- check, if that's the first attempt to mount a volume of the server[/COLOR]
		[B]if[/B] [COLOR=#4f8f00]firstMount[/COLOR] [B]then[/B]
			[B]try[/B]
[COLOR=#5E6161][COLOR=#000000]				[/COLOR]--first try to mount[/COLOR]
				[COLOR=#012fbe][B]mount volume[/B][/COLOR] "afp://" & [COLOR=#4f8f00]serv[/COLOR] & "._afpovertcp._tcp.local/" & [COLOR=#4f8f00]vol[/COLOR]
			[B]end[/B] [B]try[/B]
		[B]else[/B]
			[COLOR=#012fbe][B]mount volume[/B][/COLOR] "afp://" & [COLOR=#4f8f00]serv[/COLOR] & "._afpovertcp._tcp.local/" & [COLOR=#4f8f00]vol[/COLOR]
		[B]end[/B] [B]if[/B]
	[B]end[/B] [B]if[/B]
[COLOR=#4F8F00][COLOR=#000000]	[B]set[/B] [/COLOR]firstMount[COLOR=#000000] [B]to[/B] [/COLOR][COLOR=#5d3292]false[/COLOR][/COLOR]
	
	
[B]end[/B] [B]if[/B]


[COLOR=#5E6161]------------------------------------------------------------------------------------------------[/COLOR]
[COLOR=#4F8F00][COLOR=#000000][B]on[/B] [/COLOR]checkServer[COLOR=#000000]([/COLOR]serv[COLOR=#000000])[/COLOR][/COLOR]
	[B]try[/B]
		[COLOR=#012fbe][B]do shell script[/B][/COLOR] "ping -t2 -c1 " & [COLOR=#4f8f00]serv[/COLOR]
		[B]return[/B] [COLOR=#5d3292]true[/COLOR]
	[B]on[/B] [B]error[/B]
		[B]return[/B] [COLOR=#5d3292]false[/COLOR]
	[B]end[/B] [B]try[/B]
[COLOR=#4F8F00][COLOR=#000000][B]end[/B] [/COLOR]checkServer[/COLOR]
[COLOR=#5E6161]------------------------------------------------------------------------------------------------[/COLOR]
[COLOR=#4F8F00][COLOR=#000000][B]on[/B] [/COLOR]checkWiFi[COLOR=#000000]([/COLOR]SSID[COLOR=#000000])[/COLOR][/COLOR]
	[B]set[/B] [COLOR=#4f8f00]aSSID[/COLOR] [B]to[/B] 1
	[COLOR=#012fbe][B]do shell script[/B][/COLOR] "ioreg -l -n AirPortDriver | grep IO80211SSID  | sed 's/^.*= \"\\(.*\\)\".*$/\\1/; s/ /_/g'"
	[B]set[/B] [B]the[/B] [COLOR=#4f8f00]aSSID[/COLOR] [B]to[/B] [COLOR=#812fdc]result[/COLOR]
	[B]if[/B] [COLOR=#4f8f00]aSSID[/COLOR] [B]is[/B] [B]equal to[/B] [COLOR=#4f8f00]SSID[/COLOR] [B]then[/B]
		[B]return[/B] [COLOR=#5d3292]true[/COLOR]
	[B]else[/B]
		[B]return[/B] [COLOR=#5d3292]false[/COLOR]
	[B]end[/B] [B]if[/B]
[COLOR=#4F8F00][COLOR=#000000][B]end[/B] [/COLOR]checkWiFi[/COLOR]
[COLOR=#5E6161]------------------------------------------------------------------------------------------------[/COLOR]