Kyhz
Chapuzas Junior
- Registrado
- 11 Feb 2016
- Mensajes
- 596
- Puntos
- 43
Debido a que no he encontrado ningun temporizador de apagado para Mac me he aventurado a hacerlo con AppleScript
He aconseguido programar el apagado y que este se haga, pero no consigo añadir opción de cancelar el apagado...
De momento tengo esto que funciona:
He porbado con añadir:
Pero no se apaga cuando tengo algo en pantalla completa (supongo que el display dialog hará conflicto).
Alguien sabe si hay alguna alternativa para cancelar el apagado?
EDIT: Aprovecho para preguntar también si hay alguna manera para hacer que al volver a encender el ordenador no lo haga con las aplicaciones que estaban abiertas al cerrar. (Aveces se enciende con el AppleScript abierto y crea un bucle de apagados...)
He aconseguido programar el apagado y que este se haga, pero no consigo añadir opción de cancelar el apagado...
De momento tengo esto que funciona:
Código:
[COLOR=#000000][FONT=Verdana][B]property[/B] [COLOR=#4e8f00]pIntTimeout[/COLOR] : 3[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana][B]property[/B] [COLOR=#4e8f00]pIntTimeAmount[/COLOR] : ""[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana][B]property[/B] [COLOR=#4e8f00]pDateGoal[/COLOR] : ""[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]
[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana][B]on[/B] [COLOR=#0433ff][B]run[/B][/COLOR][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]set[/B] [COLOR=#4e8f00]pDateGoal[/COLOR] [B]to[/B] ""[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]set[/B] [COLOR=#4e8f00]blnValid[/COLOR] [B]to[/B] [COLOR=#812fdc][I]false[/I][/COLOR][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]repeat[/B] [B]until[/B] [COLOR=#4e8f00]blnValid[/COLOR][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]set[/B] [COLOR=#4e8f00]recDialog[/COLOR] [B]to[/B] [COLOR=#012fbe][B]display dialog[/B][/COLOR] "Minutos hasta el apagado:" [COLOR=#012fbe]default answer[/COLOR] [COLOR=#4e8f00]pIntTimeAmount[/COLOR] [COLOR=#012fbe]buttons[/COLOR] {"Cancel", "Ok"} [COLOR=#012fbe]default button[/COLOR] 2
[/FONT][/COLOR][COLOR=#000000][FONT=Verdana][B] if[/B] [/FONT][/COLOR][COLOR=#5730BE][FONT=Verdana]button returned[/FONT][/COLOR][COLOR=#000000][FONT=Verdana] [B]of[/B] [/FONT][/COLOR][COLOR=#4E8F00][FONT=Verdana]recDialog[/FONT][/COLOR][COLOR=#000000][FONT=Verdana] [B]is[/B] "Cancel" [B]then[/B] [/FONT][/COLOR][COLOR=#0433FF][FONT=Verdana][B]quit[/B][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]try[/B][/FONT][/COLOR]
[COLOR=#4E8F00][FONT=Verdana][COLOR=#000000] [B]set[/B] [/COLOR]pIntTimeAmount[COLOR=#000000] [B]to[/B] [/COLOR][COLOR=#5730be]text returned[/COLOR][COLOR=#000000] [B]of[/B] [/COLOR]recDialog[COLOR=#000000] [B]as[/B] [/COLOR][COLOR=#0433ff][I]integer[/I][/COLOR][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]if[/B] ([COLOR=#4e8f00]pIntTimeAmount[/COLOR] > 0) [B]then[/B][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]set[/B] [COLOR=#4e8f00]blnValid[/COLOR] [B]to[/B] [COLOR=#812fdc][I]true[/I][/COLOR][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]else[/B][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]error[/B][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]end[/B] [B]if[/B][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]on[/B] [B]error[/B][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [COLOR=#012fbe][B]display dialog[/B][/COLOR] "Error - Tiene que ser numero mas grande de 0" [COLOR=#012fbe]buttons[/COLOR] {"Ok"} [COLOR=#012fbe]default button[/COLOR] 1[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]end[/B] [B]try[/B][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]end[/B] [B]repeat[/B][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]set[/B] [COLOR=#4e8f00]strMinute[/COLOR] [B]to[/B] " minuto"[/FONT][/COLOR]
[COLOR=#4E8F00][FONT=Verdana][COLOR=#000000] [B]if[/B] ([/COLOR]pIntTimeAmount[COLOR=#000000] > 1) [B]then[/B] [B]set[/B] [/COLOR]strMinute[COLOR=#000000] [B]to[/B] [/COLOR]strMinute[COLOR=#000000] & "s"[/COLOR][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [COLOR=#012fbe][B]display dialog[/B][/COLOR] "El ordenador se apagará en " & [COLOR=#4e8f00]pIntTimeAmount[/COLOR] & [COLOR=#4e8f00]strMinute[/COLOR] & "!" [COLOR=#012fbe]buttons[/COLOR] {"Ok"} [COLOR=#012fbe]default button[/COLOR] 1 [COLOR=#012fbe]giving up after[/COLOR] [COLOR=#4e8f00]pIntTimeout[/COLOR][/FONT][/COLOR]
[COLOR=#4E8F00][FONT=Verdana][COLOR=#000000] [B]set[/B] [/COLOR]pDateGoal[COLOR=#000000] [B]to[/B] ([/COLOR][COLOR=#012fbe][B]current date[/B][/COLOR][COLOR=#000000]) + ([/COLOR]pIntTimeAmount[COLOR=#000000] * 60)[/COLOR][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana][B]end[/B] [COLOR=#0433ff][B]run[/B][/COLOR][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]
[/FONT][/COLOR]
[COLOR=#0433FF][FONT=Verdana][COLOR=#000000][B]on[/B] [/COLOR][B]idle[/B][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]try[/B][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]if[/B] (([COLOR=#012fbe][B]current date[/B][/COLOR]) >= [COLOR=#4e8f00]pDateGoal[/COLOR]) [B]then[/B][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]tell[/B] [COLOR=#0433ff][I]application[/I][/COLOR] "Finder" [B]to[/B] [COLOR=#0433ff][B]shut down[/B][/COLOR][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]end[/B] [B]if[/B][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]end[/B] [B]try[/B][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]return[/B] 1[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana][B]end[/B] [/FONT][/COLOR][COLOR=#0433FF][FONT=Verdana][B]idle
[/B][/FONT][/COLOR]
He porbado con añadir:
Código:
[COLOR=#0433FF][FONT=Verdana][COLOR=#000000][B]on[/B] [/COLOR][B]idle[/B][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]try[/B][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] [B]if[/B] (([COLOR=#012fbe][B]current date[/B][/COLOR]) >= [COLOR=#4e8f00]pDateGoal[/COLOR]) [B]then[/B][/FONT][/COLOR]
[U][COLOR=#000000][FONT=Verdana] [B]set[/B] [COLOR=#4e8f00]cancelation[/COLOR] [B]to[/B] [COLOR=#012fbe][B]display dialog[/B][/COLOR] "El ordenador está a punto de apagarse" [COLOR=#012fbe]buttons[/COLOR] {"Cancel"} [COLOR=#012fbe]default button[/COLOR] 1 [COLOR=#012fbe]giving up after[/COLOR] 10[/FONT][/COLOR]
[I][COLOR=#4E8F00][FONT=Verdana][COLOR=#000000] if button returned of cancelation is "Cancel" then quit[/COLOR][/FONT][/COLOR][/I][/U]
[B][COLOR=#000000][FONT=Verdana] tell [COLOR=#0433ff][I]application[/I][/COLOR] "Finder" to [COLOR=#0433ff]shut down[/COLOR][/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] end if[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] end try[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana] return 1[/FONT][/COLOR]
[/B][COLOR=#000000][FONT=Verdana][B]end [/B][COLOR=#0433ff][B][B]idle[/B]
[/B][/COLOR][/FONT][/COLOR]
Pero no se apaga cuando tengo algo en pantalla completa (supongo que el display dialog hará conflicto).
Alguien sabe si hay alguna alternativa para cancelar el apagado?
EDIT: Aprovecho para preguntar también si hay alguna manera para hacer que al volver a encender el ordenador no lo haga con las aplicaciones que estaban abiertas al cerrar. (Aveces se enciende con el AppleScript abierto y crea un bucle de apagados...)