Go Back   The macosxhints Forums > OS X Help Requests > System



Reply
 
Thread Tools Rate Thread Display Modes
Old 03-03-2002, 09:37 AM   #1
JoelNelson
Prospect
 
Join Date: Mar 2002
Location: Nebraska
Posts: 18
Question AppleScript to restart OS X in OS 9

I read on the Mac OS X Hints site that there is a way to AppleScript OS 9 to restart in OS X (http://www.macosxhints.com/article.p...10416184548354).
Is there a way to write a script for OS X to restart in OS 9?

JoelNelson is offline   Reply With Quote
Old 03-03-2002, 10:04 AM   #2
rusto
MVP
 
Join Date: Jan 2002
Location: Boston, MA
Posts: 1,489
Yea, see this article:

http://www.macosxhints.com/article.p...20302215826526
__________________
:: 3.4GHz Core i7 iMac 4GB RAM :: Black MacBook SR :: 10.7.2 :: iPhone 4 / iOS 5 ::
rusto is offline   Reply With Quote
Old 03-03-2002, 10:06 AM   #3
meancode
Triple-A Player
 
Join Date: Jan 2002
Location: Bowling Green, Ohio
Posts: 212
yes, someone just posted it at the macosxhints site. you can do the do shell script applescript, and if you do not want to use sudo, wich will prompt for an admin password, you can use this:
Code:
password "YourPWHere" with administrator privileges
you can then save it as a run only script. as posted as a comment on that hint, it would be nice to get the startup disk from nvram -p so you could do an if then statement in applescript.

http://www.macosxhints.com/article.p...20302215826526

it uses the bless shell command. very usefull. check out mike bombich's site for more useful unix commands (he has put together a list of ones that are useful for lab admins)

http://www.bombich.com/mactips/commands.html
__________________
Ken Edwards
Breaking Windows (Personal Blog)
meancode is offline   Reply With Quote
Old 03-03-2002, 03:40 PM   #4
JoelNelson
Prospect
 
Join Date: Mar 2002
Location: Nebraska
Posts: 18
I am not very familiar with AppleScript or command line on OS X (I am much more familiar with OS 9). What code do I enter to create this script? Could someone e-mail the script to me as an attachment? E-mail
JoelNelson is offline   Reply With Quote
Old 03-03-2002, 04:01 PM   #5
meancode
Triple-A Player
 
Join Date: Jan 2002
Location: Bowling Green, Ohio
Posts: 212
naw, we are not gonna email it, then the rest of the board wouldn't get to see it, and whats the fun in that? we if you are not very familiar with the command line that looking at the bless command is probably pretty confusing. i am writing the apple script right now, and will post it here when i am done.
__________________
Ken Edwards
Breaking Windows (Personal Blog)
meancode is offline   Reply With Quote
Old 03-03-2002, 04:31 PM   #6
rusto
MVP
 
Join Date: Jan 2002
Location: Boston, MA
Posts: 1,489
Exclamation

NOTE: In my experience, the "do shell script" does not work when an AppleScript is saved as an application. Your best bet is to use one of these 3 methods to launch it "like an app":

1) DragThing
2) Script Runner
3) ScriptMenu
__________________
:: 3.4GHz Core i7 iMac 4GB RAM :: Black MacBook SR :: 10.7.2 :: iPhone 4 / iOS 5 ::
rusto is offline   Reply With Quote
Old 03-03-2002, 04:53 PM   #7
meancode
Triple-A Player
 
Join Date: Jan 2002
Location: Bowling Green, Ohio
Posts: 212
really rusto? ive had no problems. one thing to note when you use do shell script you are not performing it is you default shell (tcsh) so that can have some wonky effects.

ive got this apple script up and running and if i check in the system pref pane for startup disk it DOES change the startup system folder. i am going to restart and test thing thing out before i post. will post in a few minutes.
__________________
Ken Edwards
Breaking Windows (Personal Blog)
meancode is offline   Reply With Quote
Old 03-03-2002, 05:10 PM   #8
JoelNelson
Prospect
 
Join Date: Mar 2002
Location: Nebraska
Posts: 18
Thanks for the help! The script sounds good.

ÊÊÊWith OS X my current default OS, if I
a> change startup system folder to OS 9 in the OS X Startup Disk panel
b> then restart in OS 9
will the OS 9 control panel also show that the default system folder has been changed to OS 9?
and
c> when from OS 9 I change the startup system folder back to OS X
d> and boot into OS X will it have remembered the settings change from OS 9?

ÊÊÊÊI will be frequently booting into OS 9 but since I will be using OS X even more frequently I want it to be the default OS. However, since I will use OS 9 a lot (with Virtual PC 3.0.3 so I can't just use Classic) I want an easy way to go back and forth between the two OSes. I will also have others in my family using the computer and they will have to restart in OS 9 also... hopefully this script will work since I don't think opening the control panels each time would be very popular.
JoelNelson is offline   Reply With Quote
Old 03-03-2002, 05:26 PM   #9
rusto
MVP
 
Join Date: Jan 2002
Location: Boston, MA
Posts: 1,489
Quote:
Originally posted by meancode
really rusto? ive had no problems. one thing to note when you use do shell script you are not performing it is you default shell (tcsh) so that can have some wonky effects.

Right, "do shell script" operates in the sh shell not tcsh.
__________________
:: 3.4GHz Core i7 iMac 4GB RAM :: Black MacBook SR :: 10.7.2 :: iPhone 4 / iOS 5 ::
rusto is offline   Reply With Quote
Old 03-03-2002, 06:38 PM   #10
meancode
Triple-A Player
 
Join Date: Jan 2002
Location: Bowling Green, Ohio
Posts: 212
to answer your question.

OS 9 and OS X will show that the default system folder has been changed. yes they will both update acordingly.

here is the script. its not the prettiest thing, but it gets the job done.
Code:
tell application "Finder"
	activate
	display dialog "Change your startup disk to:" buttons {"Mac OS X", "Mac OS 9.1", "Mac OS 9.2.2"} default button "Mac OS 9.1"
	set the user_choice to the button returned of the result
	if the user_choice is "Mac OS X" then
		do shell script "/usr/sbin/bless -folder '/System/Library/CoreServices' -setOF" password "YourAdminPW" with administrator privileges
	else if the user_choice is "Mac OS 9.1" then
		do shell script "/usr/sbin/bless -folder9 '/Volumes/Mac OS 9/System Folder' -setOF" password "YourAdminPW" with administrator privileges
	else if the user_choice is "Mac OS 9.2.2" then
		do shell script "/usr/sbin/bless -folder9 '/System Folder' -setOF" password "YourAdminPW" with administrator privileges
	end if
end tell
you will have to change some things here:

YourAdminPW # change this to your admin password
/Volumes/Mac OS 9/System Folder # change to the path of your OS 9 partition. interestingly enough you do not need escape charectors for the spaces.

just copy this code and paste it into Script Editor, then save it as an run only application (this has your admin password in it, so you dont want other snooping into it, you might also want to give group and everyone only execute privs to the script), make sure that Never Show Startup Screen is checked. i suggest saving it into you Scripts folder, every user should have one at ~/Library/Scripts. then you can access this from the Script Menu. if there are multiple accounts on this machine, you would want to put this script in the main scripts folder wich is at /Library/Scripts.

now to explain what the 3 buttons do. the choices are Mac OS X, Mac OS 9.1 and Mac OS 9.2.2. i have on my main partition Mac OS 10.1.3 and Mac OS 9.2.2, and then on a secondary partition Mac OS 9.1, wich i use when i want to reboot into 9. you may or may not want all 3 options, in wich case you can delete the last else if, also be sure to delete that choice out of the display dialog line as well. if you do not want the third choice the script would look like this:
Code:
tell application "Finder"
	activate
	display dialog "Change your startup disk to:" buttons {"Mac OS X", "Mac OS 9"} default button "Mac OS 9"
	set the user_choice to the button returned of the result
	if the user_choice is "Mac OS X" then
		do shell script "/usr/sbin/bless -folder '/System/Library/CoreServices' -setOF" password "YourAdminPW" with administrator privileges
	else if the user_choice is "Mac OS 9" then
		do shell script "/usr/sbin/bless -folder9 '/Volumes/Mac OS 9/System Folder' -setOF" password "YourAdminPW" with administrator privileges
	end if
end tell


NOTE: this script will not work if used by a non admin account unless you put them into the group that can use the sudo cammand. to see what i mean login as a non admin, go to the terminal and type: sudo ls. you will get a message saying that you cannot use the sudo command, wich IS NEEDED to pull this swich-the-startup-volume thingy off. the bless command HAS to be run as root. no way around that one.

setting other accounts up as admin accounts is surely not a very safe way to go, especialy if they do not know what they are doing. i am pretty sure a user has to be in the 'wheel' or the 'admin' group. if you make a user an admin user in the users pref pane, that user is put into these groups for you. maybe someone else can share some insight on how to allow a non admin account the ability to use sudo, and not have full admin privs. i would like to know myself.

i am really glad this tip was posted on the main hints site as i cannot stand waiting a half hour (well not that long but still) to chose my startup volume. also note i am not that great at apple script, i am sure there are better ways of doing this.

i got excellent results in testing this out. it worked great for changing the startup disk, i checked every time after i ran the script. i also rebooted to make sure it worked correctly as intended, and it did. the only snafu i came across was this: the first time i tryed to boot into OS 9.2.2 from OS X (after running the script) i got a question mark icon, and it seemed to roll over to the OS 9.1 system folder. so what i did was rebooted from OS 9.1 to OS 9.2.2, had no problems there. i then rebooted from 9.2.2 to OS X. the second time i ran the script and set it to boot from 9.2.2 i had no problems, no blinking question marks. same held true for the 3rd, 4th, 5th and 6th tries. i dont know why it did this. but i wanted to let you know this happened to me. i hope this helps, it sure makes my life easier now, man i love apple script. i learn more and more all the time.

about Virtual PC. you are not missing much by not using VPC 5 in OS X (other than the added features that VPC 4 and 5 have over version 3). it is a dog when run nativly in OS X. i still boot into OS 9 to use VPC 5 in OS 9, even though 5 is native in X. it slow as molassis in january. no kidding.
__________________
Ken Edwards
Breaking Windows (Personal Blog)
meancode is offline   Reply With Quote
Old 03-03-2002, 06:57 PM   #11
rusto
MVP
 
Join Date: Jan 2002
Location: Boston, MA
Posts: 1,489
Nice job, Ken!
__________________
:: 3.4GHz Core i7 iMac 4GB RAM :: Black MacBook SR :: 10.7.2 :: iPhone 4 / iOS 5 ::
rusto is offline   Reply With Quote
Old 03-03-2002, 07:10 PM   #12
meancode
Triple-A Player
 
Join Date: Jan 2002
Location: Bowling Green, Ohio
Posts: 212
thanks rusto , i really impressed myself as well. id have to say thats the first script i have ever started from scratch.

btw here is an adition to the script to add a standard icon to the window, change this line:
Code:
	display dialog "Change your startup disk to:" buttons {"Mac OS X", "Mac OS 9.1", "Mac OS 9.2.2"} default button "Mac OS 9.1"
to this:
Code:
	display dialog "Change your startup disk to:" buttons {"Mac OS X", "Mac OS 9.1", "Mac OS 9.2.2"} default button "Mac OS 9.1" with icon note
it just adds a little more user friendly feel to it.
__________________
Ken Edwards
Breaking Windows (Personal Blog)
meancode is offline   Reply With Quote
Old 03-03-2002, 07:31 PM   #13
JoelNelson
Prospect
 
Join Date: Mar 2002
Location: Nebraska
Posts: 18
Thanks! I have no partitions on my drive. I only have OS X 10.1.3 and OS 9.2.2. Will this script still work?
JoelNelson is offline   Reply With Quote
Old 03-03-2002, 08:09 PM   #14
meancode
Triple-A Player
 
Join Date: Jan 2002
Location: Bowling Green, Ohio
Posts: 212
yes it will. here is a modified version for you, so you dont have to get muddy editing that thing
Code:
tell application "Finder"
	activate
	display dialog "Change your startup disk to:" buttons {"Mac OS X", "Mac OS 9"} default button "Mac OS 9" with icon note
	set the user_choice to the button returned of the result
	if the user_choice is "Mac OS X" then
		do shell script "/usr/sbin/bless -folder '/System/Library/CoreServices' -setOF" password "xxxxx" with administrator privileges
	else if the user_choice is "Mac OS 9" then
		do shell script "/usr/sbin/bless -folder9 '/System Folder' -setOF" password "xxxxxx" with administrator privileges
	end if
end tell
__________________
Ken Edwards
Breaking Windows (Personal Blog)

Last edited by meancode; 03-03-2002 at 08:48 PM.
meancode is offline   Reply With Quote
Old 03-03-2002, 08:14 PM   #15
maclaw
Prospect
 
Join Date: Jan 2002
Posts: 35
The script is nice with the buttons, particularly for people with more than 2 alternatives. One thing I am considering is to create an "if" statement that would pick the default button based upon the current setting. This under the theory that, if you are already set to boot into 9.1 (for instance) and wanted it to stay that way, then you probably wouldn't be running the script. So the default should then be 10.1.3. But if you are currently set for 10.1.3, then you probably want the default to be 9.1 (or something else). Also, it would be nice to include a line in the dialog stating "Your current startup folder is 10.1.3 [or whatever it is]." I don't know if it's worth the trouble.

For the person who asked above, you can script the status of your current Startup Folder by using a couple of grep commands and checking the output.

For instance...
Quote:
bless -info / | grep -c "Blessed System Folder is /System/Library/CoreServices"

This line will return a value of 1 if the Startup Disk is the OS X system you are currently booted from. It will return a value of 0 if the Startup disk is anything else.
Quote:
bless -info / | grep -c "Blessed System Folder is /System Folder"

This will return a value of 1 if the OS 9 version on the same partition as your OS X boot volume is set as Startup, and 0 if it is not.
Quote:
bless -info / | grep -c "Blessed System Folder is /Volumes/Main/System Folder"

This final version will return a 1 if the OS 9.04 system on my partition "main" is set, and a 0 if it is not.

Consequently, if you run all three commands in a script only one of them will return a value of 1 at any given time. Set a variable to the value of the output and see which one equals 1. That is your current startup disk.

Of course, you will need to tailor the paths in these commands to look for the system folders on your specific system. Also, you will also need to repeat the command for every possible startup disk.

I'll actually write the script if I get some time but I thought others might at least be interested in the approach (since it was asked about). Be forewarned that I haven't actually tried this yet -- it's just an idea. But I don't see any glaring flaws. Feel free to chime in!!
maclaw is offline   Reply With Quote
Old 03-03-2002, 08:27 PM   #16
meancode
Triple-A Player
 
Join Date: Jan 2002
Location: Bowling Green, Ohio
Posts: 212
maclaw - that is exactly what i was looking for. how to get what was the current starup and do an if then so the dialog would actually be conditional to the current setting. thanks. i will tinker some more
__________________
Ken Edwards
Breaking Windows (Personal Blog)
meancode is offline   Reply With Quote
Old 03-03-2002, 08:44 PM   #17
meancode
Triple-A Player
 
Join Date: Jan 2002
Location: Bowling Green, Ohio
Posts: 212
apple script chokes on the syntax:

bless -info / | grep -c "Blessed System Folder is /System/Library/CoreServices"

though that works correctly in sh and tcsh. dont know why. if you could shed some light on this maclaw and modify the script, please do! im still tinkering with it.
__________________
Ken Edwards
Breaking Windows (Personal Blog)
meancode is offline   Reply With Quote
Old 03-03-2002, 09:32 PM   #18
meancode
Triple-A Player
 
Join Date: Jan 2002
Location: Bowling Green, Ohio
Posts: 212
now when i try and startup classic mode i get the error stating "to start classic you need OS 9.1 or later installed... i dont know how this script could have affected this, none the less this is not good. what i dad to do was bless the 9.2.2 system (with the script). so this is one side effect to doing this through a script and not manualy through the pref pain but it did work after i reblessed the 9.2.2 system all was good again.
__________________
Ken Edwards
Breaking Windows (Personal Blog)
meancode is offline   Reply With Quote
Old 03-03-2002, 09:46 PM   #19
maclaw
Prospect
 
Join Date: Jan 2002
Posts: 35
The applescript error is apparently because of the path variable referenced by applescript. The command does work in zsh so you just need to give a direct reference...

Quote:
do shell script "/usr/sbin/bless -info / | grep -c 'Blessed System Folder is /System/Library/CoreServices'"

Enter this single line in a new script editor window and you should get back a response of 0 (or 1, depending on what Startup Disk you have set). Either way, do that quick test and then worry about setting it to a variable and incorporating into your script.
maclaw is offline   Reply With Quote
Old 03-03-2002, 09:54 PM   #20
JoelNelson
Prospect
 
Join Date: Mar 2002
Location: Nebraska
Posts: 18
Is this script still the correct one to use or are the above bugs relating to this script?

tell application "Finder"
activate
display dialog "Change your startup disk to:" buttons {"Mac OS X", "Mac OS 9"} default button "Mac OS 9" with icon note
set the user_choice to the button returned of the result
if the user_choice is "Mac OS X" then
do shell script "/usr/sbin/bless -folder '/System/Library/CoreServices' -setOF" password "xxxxx" with administrator privileges
else if the user_choice is "Mac OS 9" then
do shell script "/usr/sbin/bless -folder9 '/System Folder' -setOF" password "xxxxxx" with administrator privileges
end if
end tell
JoelNelson is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 06:21 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.