2010-04-24 8 views
7

No tengo un enrutador Wi-Fi, por lo que cuando estoy en casa tengo que convertir mi computadora portátil en una fuente Wi-Fi para que tanto yo como mi compañero podamos acceder a Internet .Cómo iniciar/detener el uso compartido de Internet con AppleScript

Sin embargo, durante los días que trabajo en una cafetería y requieren el uso de su Wi-Fi.

Estoy ejecutando Snow Leopard y me resulta estúpidamente engorroso apagar y encender constantemente, primero uso compartido de Internet y luego mi conexión Wi-Fi.

¿Alguna idea para una solución AppleScript rápida y sucia?

Respuesta

6

Puede usar launchctl para iniciar o detener mediante programación el servicio de Internet Sharing.

El siguiente AppleScript comenzará compartida a Internet:

do shell script "/bin/launchctl load -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges 

La siguiente AppleScript se detendrá compartida a Internet:

do shell script "/bin/launchctl unload -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges 
4

estoy usando este AppleScript de Automator para que pueda utilizar fácilmente como un servicio y darle un atajo de teclado.

Toggle compartida a Internet:

register_growl() 

try 
    if isRunning("InternetSharing") then 
     do shell script "launchctl unload -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges 

     if isRunning("InternetSharing") then 
      error "Internet Connection Sharing was Not Disabled" 
     else 
      my growlnote("Success", "Internet Connection Sharing Disabled") 
     end if 

    else 
     do shell script "launchctl load -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges 

     if isRunning("InternetSharing") then 
      my growlnote("Success", "Internet Connection Sharing Enabled") 
     else 
      error "Internet Connection Sharing was Not Enabled" 
     end if 

    end if 

on error errMsg 
    my growlnote("Error", errMsg) 

end try 

on isRunning(processName) 
    try 
     return 0 < length of (do shell script "ps ax | grep -v grep | grep " & processName) 
    on error 
     return false 
    end try 
end isRunning 

on register_growl() 
    try 
     tell application "GrowlHelperApp" 
      set the notificationsList to {"Success", "Warning", "Error"} 
      register as application "Toggle Internet Connection Sharing" all notifications notificationsList default notifications notificationsList icon of application "Sharing" 
     end tell 
    end try 
end register_growl 

on growlnote(growltype, str) 
    try 
     tell application "GrowlHelperApp" 
      notify with name growltype title growltype description str application name "Toggle Internet Connection Sharing" 
     end tell 
    end try 
end growlnote 

soy cross-posting presente en la bolsa de pila de Apple debido a que la pregunta fue hecha en ambos lugares.

+0

+1 ¡para una solución sofisticada pero fácil de usar! ¡Gracias! – pille

1

No estoy seguro si usted todavía está buscando una solución, pero ... aquí es un AppleScript para habilitar o deshabilitar el uso compartido de Internet

tell application "System Preferences" 
    activate 
    reveal (pane id "com.apple.preferences.sharing") 
end tell 

tell application "System Events" 
    tell process "System Preferences" 
     try 
      click checkbox of row 11 of table 1 of scroll area of group 1 of window "Sharing" 

      if checkbox of row 11 of table 1 of scroll area of group 1 of window "Sharing" is equal to 1 then 
       repeat until sheet of window 1 exists 
        delay 0.5 
       end repeat 

      end if 

      if (sheet of window 1 exists) then 
       click button "Start" of sheet of window 1 

      end if 

      tell application "System Preferences" to quit 
      activate (display dialog "Internet Sharing preferences sucessfully flipped") 

     on error 

      activate 
      display dialog "something went wrong in automation but you are probably in the right menu..." 
      return false 
     end try 

    end tell 

end tell 

también voy a publicar esto en el puesto de bolsa manzana pila.

Cuestiones relacionadas