¡Expertos!
Soy nuevo en el script de Apple y lucho con su complejidad ... Pero tal vez alguien pueda ayudar. Lo que quiero hacer con mi iMac:
El iMac se usa para funcionar como una presentación de diapositivas HighEnd para el trabajo de un artista. Es extremadamente importante que el iMac obtenga la hora correcta para mostrar la presentación de diapositivas.
Entonces, ¿qué debe hacer el iMac?
iMac se despierta todas las mañanas a las 8 a. m. y se duerme a las 11 p. m. (hecho por Energysaver)
iMac activa y desactiva Wi-Fi (consulte el script 1 a continuación)
¡Cualquier ayuda y sugerencia sería muy apreciada! andreas
Lo que tengo:
--GUIÓN 1
set status to do shell script "networksetup -getairportpower en1"
if status ends with "On" then
do shell script "networksetup -setairportpower en1 off; sleep 2"
end if
set status to do shell script "networksetup -getairportpower en1"
if status ends with "Off" then
do shell script "networksetup -setairportpower en1 on"
end if
--GUIÓN 2
tell application "Safari" activate
end tell
--SCRIPT 3 haciendo clic en la casilla para aceptar los términos de uso
to clickID(theId)
tell application "Safari"
do JavaScript "document.getElementById('" & theId & "').click();" in document 1
end tell
end clickID
--Se necesita SCRIPT 4 para obtener la hora, esperar e iniciar el protector de pantalla
set ntpdPID to do shell script "pgrep ntpd; exit 0"
if ntpdPID is not "" then
do shell script "systemsetup -setusingnetworktime On" with administrator privileges
end if
try
tell application id "com.apple.Screensaver.engine" to launch
end try
repeat 2 times
set status to do shell script "networksetup -getairportpower en0"
if status ends with "On" then
do shell script "networksetup -setairportpower en1 off"
delay 2
else
do shell script "networksetup -setairportpower en1 on"
end if
end repeat
tell application "Safari" to activate
Use el código @CJK para conectarse. Luego use el Script 3 para aceptar los términos y condiciones.
Safari> Preferencias> Avanzado> Mostrar el menú Desarrollar en la barra de menú
Desarrollar > Permitir JavaScript de Apple Events
3.
tell application "Safari"
activate
make new document with properties {URL: "http://captive.apple.com"}
if not (exists document 1) then reopen
tell current tab of window 1 to set URL to "https://stackoverflow.com/questions/24500011/how-to-wait-for-webpage-to-fully-load-before-proceeding-script"
set the_state to missing value
repeat until the_state is "complete"
set the_state to (do JavaScript "document.readyState" in document 1)
delay 0.2
end repeat
set theId to "WillBeAddedOnceCodeIsAddedInQuestion"
do JavaScript "document.getElementById('" & theId & "').click();" in document 1
end tell
Si el script funciona, haga lo siguiente:
Método Cron (Depreciado)
1.
export VISUAL=nano; crontab -e
2. Copia y pega lo siguiente
0 9 * * * osascript /path/to/YourAppleScript.scpt
3. Presione ^O (Control + O)
Nota: Cron no se ejecutará si la computadora está dormida
lanzado
sudo nano /Librería/LaunchDaemons/com.miempresa.plist
Copia y pega lo siguiente:
<?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>com.mycompany.daemon</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/osascript</string>
<string>/path/to/YourAppleScript.scpt</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>9</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</dict>
</plist>
Presiona ^O (Control + O)
Presiona Entrar
5.
sudo launchctl load -w /Librería/LaunchDaemons/com.miempresa.plist
launchd
probablemente sea preferible a cron
, el último de los cuales se considera obsoleto en macOS. StartCalendarInterval
probablemente sería la clave para usar aquí.space
cuando >
los usa, por ejemplo, Safari> Preferencias> Avanzado> Mostrar el menú Desarrollar en la barra de menú, etc.open location
no es un comando de Safari y no debe usarse dentro de un bloque de Safari tell
(o, más bien, es superfluo hacerlo). open location
abre una URL en el navegador predeterminado del sistema , que puede ser Chrome . Para abrir una URL en Safari , haga tell app "Safari" to make new document with properties {URL: "http://example.com"}
.
JBis
Alano
andreas
JBis
andreas