Re: Restarting OSX through applescript
Re: Restarting OSX through applescript
- Subject: Re: Restarting OSX through applescript
- From: Sander Tekelenburg <email@hidden>
- Date: Sat, 30 Mar 2002 18:17:33 +0100
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 11:16 -0800 UTC, on 29-03-2002, Christopher Nebel wrote:
>
On Friday, March 29, 2002, at 08:29 AM, Joel Mahaffey wrote:
>
>
> I'm having trouble writing a script to restart OSX, I'm trying to make a
>
> script to change the startup folder, and restart all in one click.
>
> The best I've done is to make it so that the applescript hangs, and
>
> once you
>
> force quit the applescript, it restarts successfully.
>
>
Mac OS X behaves exactly like Mac OS 9 in this respect. The problem is
>
that "restart" is trying to be nice and let all running applications
>
finish their work before restarting, and if you just say 'tell
>
application "Finder" to restart', the script won't finish until the
>
restart is done -- a Catch-22.
>
>
The solution is to put the "restart" command inside an "ignoring
>
application responses" block. (Maybe we should make it always act this
>
way -- it's useless otherwise.)
I'm confused. "tell app Finder to restart" works perfectly fine for me
without wrapping it in an "ignoring application responses" block. The only
caveat is that if some application is *activated*, that prohibits the Finder
from restarting.
As I understand it, exactly because of this activation issue, Mac OS 9.1/AS
1.6 introduced the possibility to ask the Finder for its execution state
(starting up/running/rebuilding desktop/copying/restarting/quitting).
This brings me to something I had been planning to ask about: When you have
items in the Shutdown Items folder that activate an app, they will cancel the
restart/shutdown. I'm trying to work around that by making use of the
Finder's "get execution state". My approach is to have a stay-open applet in
the Shutdown Items folder. It asks the Finder for its execution state, then
waits until all processes that are launched from the Shutdown Items folder
have quit, and then tells the Finder to resume what it was doing.
I'm running into 2 problems with this:
1) Half the time, the Finder returns the raw code when asked for the
execution state. Instead of "restarting", it returns <<constant ****ese6>>
and instead of "quitting" it returns <<constant ****ese7>>. Once you know
ths, you can catch it and work wih it. But it looks like a bug to me.
2) My approach works perfectly well with "restarting", but it does not work
with "quitting". After all other Shutdown Items have quit, this stay-open
applet just stays open and the machine is never shut down.
Tested under both Mac OS 9.2.1 and 9.1 (both with AppleScript 1.6) with the
exact same results.
Here is the script:
(* start script *)
global theApps, theState, myName
tell me to activate
(* Else, if no Shutdown Item activates anything, Finder will complain user
already did a restart/shutdown *)
set myPath to (path to me) as text
set oldTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
try
set myName to last text item of myPath
on error m number n
set AppleScript's text item delimiters to oldTIDs
end try
set AppleScript's text item delimiters to oldTIDs
tell application "Finder"
set theApps to (name of every item of shutdown items folder)
end tell
on idle
tell application "Finder"
set theState to (get execution state)
end tell
my deBug(theState)
if ((theState as string) = "restarting") or ((theState as string) =
"+constant ****ese6;") ,
or ((theState as string) = "quitting") or ((theState as string) =
"+constant ****ese7;") then
tell application "Finder"
set theProcesses to name of every process whose name is not myName
end tell
repeat with i in theApps
if (i is in theProcesses) then
exit repeat
else
try
set theApps to items 2 thru -1 of theApps
on error number -1728 -- There's only 1 item in theApps
set theApps to theApps
end try
end if
end repeat
if (count of items of theApps) = 1 then
my QuitReboot()
end if
end if
end idle
on QuitReboot()
try
if (theState as string) = "restarting" or ((theState as string) =
"+constant ****ese6;") then
tell application "Finder" to restart
else if (theState as string) = "quitting" or ((theState as string) =
"+constant ****ese7;") then
tell application "Finder" to shutdown
else
tell me to quit
end if
on error m number n
deBug(n & return & return & (m as text))
end try
end QuitReboot
on deBug(theDialog)
set theLog to open for access file ((path to desktop as string) &
"Reboot/Shutdown log") with write permission
try
write (return & (current date) & ": " & (theDialog as text)) to theLog
starting at eof
on error m number n
close access theLog
display dialog n & return & return & m as text
end try
close access theLog
end deBug
(* end script *)
Can anyone confirm this? Am I doing something silly? Any solutions?
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <
http://www.pgp.com>
iQA/AwUBPKXzAesywKfXgqKdEQKQaQCg72Y6CfRLBtBHTy61rwCoqUoZIyAAoJcy
ncD66uoYzwFb8uuf/R1CtWTU
=t0Cm
-----END PGP SIGNATURE-----
--
Sander Tekelenburg, <
http://www.euronet.nl/~tekelenb/>
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.