2010-04-24 11 views
7

का उपयोग कर इंटरनेट शेयरिंग को कैसे शुरू/बंद करना है मेरे पास वाई-फाई राउटर नहीं है, इसलिए जब घर पर मुझे अपने लैपटॉप को वाई-फाई स्रोत में बदलना होगा ताकि दोनों मेरे और मेरे साथी इंटरनेट तक पहुंच सकें ।ऐप्पलस्क्रिप्ट

हालांकि दिनों के दौरान मैं कॉफी शॉप में काम करता हूं और उनके वाई-फाई के उपयोग की आवश्यकता होती है।

मैं हिम तेंदुए चला रहा हूं और मुझे लगातार इंटरनेट चालू करने और फिर मेरी वाई-फाई बंद करने के लिए बेवकूफ रूप से बोझिल लगता है।

त्वरित 'एन' गंदे ऐप्पलस्क्रिप्ट समाधान के लिए कोई विचार?

उत्तर

6

प्रोग्रामिंग शुरू करने या इंटरनेट साझाकरण सेवा को रोकने के लिए आप launchctl का उपयोग कर सकते हैं।

निम्नलिखित AppleScript शुरू कर देंगे इंटरनेट शेयरिंग:

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

निम्नलिखित AppleScript बंद हो जाएगा इंटरनेट शेयरिंग:

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

मैं स्वचालक से इस AppleScript उपयोग कर रहा हूँ ताकि मैं आसानी से इसे के रूप में उपयोग कर सकते हैं एक सेवा और इसे एक कीबोर्ड शॉर्टकट दें।

टॉगल इंटरनेट शेयरिंग:

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 

मैं cross-posting इस हूं एप्पल ढेर एक्सचेंज पर क्योंकि सवाल दोनों स्थानों में पूछा गया था।

+0

+1 एक परिष्कृत, अभी तक उपयोग में आसान समाधान के लिए +1! धन्यवाद! – pille

1

सुनिश्चित नहीं हैं कि क्या आप अभी भी एक समाधान की तलाश में लेकिन ... कर रहे हैं यहाँ

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 

सक्षम या अक्षम करने इंटरनेट साझा करने मैं भी सेब ढेर विनिमय पोस्ट पर इस पोस्ट करेंगे एक सेब स्क्रिप्ट है।

संबंधित मुद्दे