Ich suche ein Script das beim schließen des Programmes die VPN Verbindung trennen

T

thinkart23

Neues Mitglied
Thread Starter
Dabei seit
08.06.2012
Beiträge
13
Reaktionspunkte
0
Hallo zusammen,
ich bin neu hier und auch beim schreiben von Scripts.
Ich bin grad bei einem Script das eine Vpn Verbindung startet,dann "Programm XY" startet.(bis dahin habe ich es)
Wie wäre der Verlauf im Script wenn:
- Programm XY wird geschlossen
- VPN Verbindung trennen

Der Script lautet bis lang:
tell application "System Events"
tell current location of network preferences
set myConnection to the service "VPN"
if myConnection is not null then
if current configuration of myConnection is not connected then
connect myConnection
end if
end if
end tell
tell application "Skype" to activate
end tell



wer kann mir einen Tipp bzw weiter helfen?
 
Hallo,

Programm XY wird geschlossen
Notifications kannst Du mit AS nicht beobachten.

Dein Skript müsste in einer Endlosschleife laufen und bei jedem Durchgang prüfen, ob das Teilo noch läuft.
Das ist aber ziemlich uncool.

Alternative, wenn Du das mit AS umsetzen möchtest ist eine Kombination mit "Do Something When": http://www.azarhi.com/Projects/DSW/

… und wenn Du es hardcora magst, dann siehe NSWorkspace > NSWorkspaceDidTerminateApplicationNotification.

Viele Grüße
 
Hallo thinkart23,

man kann mehrere Netzwerkumgebungen anlegen welche dann unter dem Apfelmenü->Umgebungen erscheinen. Diesen kann man auch jeweils einen Shortcut zuweisen.
Den Wechsel der Umgebung kann man mit lauchd erfassen.

Terminal:

cd ~/Library/LaunchAgents/
nano org.thinkart23.LocationSwitch.plist

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>org.thinkart23.LocationSwitch</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/bin/open</string>
                <string>/Applications/LocationSwitch.app/</string>
        </array>
        <key>WatchPaths</key>
        <array>
                <string>/Library/Preferences/SystemConfiguration</string>
        </array>
</dict>
</plist>
ctrl-X
Y
Return
AppleScriptEditor öffnen

Code:
tell application "System Events"
	if (name of every application process) does not contain "Skype" then
		
		display dialog "Skype wird gestartet" giving up after 1
		tell application "Skype" to activate
	else
		display dialog "Skype wird beendet" giving up after 1
		tell application "Skype" to quit
	end if
end tell
Speichern in Programme als Programm "LocationSwitch"

den LaunchAgent mit

launchctl load /Users/thinkart23/LaunchAgents/org.thinkart23.LocationSwitch.plist

laden und die Umgebung wechseln. In der einen Hast Du den VPN und in der anderen nicht.
Es kann sein, dass das AppleScript.app mehr als einmal läuft, dann müsstest Du einen z.B. "delay 5" nach activate und quit setzen.

Gruß Andi
 
Ich danke euch erst mal für die schnellen Antworten!
Wie gesagt ich befasse mich ganz frisch mit dem script schreiben.
Der hintergedanke zu dem Script ist der,das ich das an VPN Clients verteilen möchte.
Ich bekomme es bis jetzt soweit hin:
tell application "System Events"
tell current location of network preferences
set myConnection to the service "VPN"
if myConnection is not null then
if current configuration of myConnection is not connected then
connect myConnection
end if
end if
end tell
tell application "Skype" to activate
end tell
tell application "System Events"
if (name of every application process) does not contain "Skype" then
tell current location of network preferences
if service "VPN" is in progress then
disconnect service "VPN"
end if
end tell
end if
end tell


nur wenn ich Skype schließe bleibt die VPN weiter hin verbunden.Wo ist mein Fehler?
 
Hallo thinkart23,

Du brauchst einen on idle Handler und ein stay open Script.

So müsste es gehen:

Code:
tell application "System Events"
	tell current location of network preferences
		set myConnection to the service "VPN"
		if myConnection is not null then
			if current configuration of myConnection is not connected then
				connect myConnection
			end if
		end if
	end tell
	tell application "Skype" to activate
end tell
on idle
	tell application "System Events"
		if (name of every application process) does not contain "Skype" then
			tell current location of network preferences
				if service "VPN" is in progress then
					disconnect service "VPN"
					tell me to quit
				end if
			end tell
		end if
	end tell
	return 1
end idle

Das als Programm sichern und den Haken bei Nicht automatisch beenden setzen. Jetzt wir alle Sekunde (return 1) geprüft ob Skype noch läuft...

Gruß Andi
 
Ich danke dir Andi ich werde es gleich mal Testen
 
Habe es grad mal getestet,ich bekomme eine Fehlermeldung Variable "progress" nicht definiert ebim VPN Server Verbindung schließen,hmm
 
So jetzt geht es Script lautet:
tell application "System Events"
tell current location of network preferences
set myConnection to the service "VPN"
if myConnection is not null then
if current configuration of myConnection is not connected then
connect myConnection
end if
end if
end tell
tell application "Skype" to activate
end tell
on idle
tell application "System Events"
if (name of every application process) does not contain "Skype" then
tell current location of network preferences
if service "VPN" is active then
disconnect service "VPN"
tell me to quit
end if
end tell
end if
end tell
return 1
end idle
 
Zurück
Oben Unten