Potrzebuję skryptu jabłkowego, który będzie włączał i wyłączał Wi-Fi w określonych odstępach czasu, powiedzmy co 10 lub 15 minut. Używam MacBookPro 2012 z systemem 10.9.5.
Potrzebuję skryptu jabłkowego, który będzie włączał i wyłączał Wi-Fi w określonych odstępach czasu, powiedzmy co 10 lub 15 minut. Używam MacBookPro 2012 z systemem 10.9.5.
Odpowiedzi:
ODKRYWACZ : Nie mogę teraz tego sprawdzić (czy to faktycznie działa), ale zrobię to później.
Skrypt do włączania / wyłączania Wi-Fi jest pobierany stąd :
try
set makiaeawirelessstatus to do shell script "networksetup -getairportpower en1"
on error
display dialog "The script did not work as intended, please check the networksetup command (in terminal) works on your system. It has been tested on mac os 10.7 (Build 11A459e). Other versions of mac os may not have this command available. Please open the applescript in applescript editor for more details." buttons {"kthxbai"}
end try
if makiaeawirelessstatus is "Wi-Fi Power (en1): On" then
do shell script "networksetup -setairportpower en1 off"
else if makiaeawirelessstatus is "Wi-Fi Power (en1): Off" then
do shell script "networksetup -setairportpower en1 on"
else
display dialog "The script did not work as intended, please check your wireless connection is specified correctly. The default in this script is en1 (please open the applescript in applescript editor for more details)" buttons {"kthxbai"}
end if
Trzeba by go edytować, aby akceptował argumenty (zrobiłbym to, ale okazałoby się, że to javascript)
Następnie, jeśli chcesz, aby skrypt działał poprawnie, użyj czegoś takiego jak LaunchAgent lub cron . Wolę LaunchAgent, ponieważ jest bardziej wyrozumiały.
Edytuj crontab roota (na przykład przez uruchomienie EDITOR=nano sudo crontab -e) i dodaj linię
*/15 * * * * ifconfig en1 down;ifconfig en1 up
gdzie en1jest identyfikator pokazany przez networksetup -listallhardwareports|awk '/^Hardware Port: (Wi-Fi|Airport)/{getline;print $2}'.
Te ifconfigkomendy wymagają praw administratora.
tell application "System Events" to tell process "SystemUIServer"
click (first menu bar item whose value of attribute "AXDescription" contains "Wi-Fi") of menu bar 1
try
click menu item 2 of menu of (first menu bar item whose value of attribute "AXDescription" contains "Wi-Fi") of menu bar 1
end try
end tell