![]() |
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? :confused: |
|
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 privilegeshttp://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 |
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
|
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.
|
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 |
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. |
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. :) |
Quote:
|
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"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"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. |
Nice job, Ken!
|
thanks rusto :D, 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"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 |
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?
|
yes it will. here is a modified version for you, so you dont have to get muddy editing that thing :D
Code:
tell application "Finder" |
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:
Quote:
Quote:
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 - 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 :)
|
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. |
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.
|
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:
|
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, you are correct, that will work. the bug i refered to is that if you do not "rebless" os 9.2.2 and try and launch classic mode, it tells you u dont got OS 9 at all, not a pretty sight. to fix this all i did was rebless (with the script) the 9.2.2 folder and i was good to go. classic mode started right up and i was using my classic apps without a hitch. i dont know why this is, but im just sayin this is the way it is.
|
Another AS to set the startup disk.
Here's a commented enhanced script that I wrote for those who don't feel like editing. I just need to find a way to get the currently blessed system folder so I can have it selected by default.
Code:
tell application "Finder" |
WOW, cool. ok i was doing the same thing to mine, im glad i was on the write track. here is the snippet i am using to get the current blessed folder.
Code:
|
meancode --
in order for classic to work, you must specify both an OS X and a classic system folder in your command when switching from OS 9 to OS X. I believe this should work... Code:
sudo /usr/sbin/bless -folder "/System/Library/CoreServices" -folder9 "/System Folder" -setOFUsing bless -info / will confirm that setting only the OS X folder will leave "No OS Classic + X blessed 9 folder" while using both will show "Classic blessed folder is /System Folder" in addition to setting the Blessed System Folder. |
I'm not personally interested in searching for available startup disks since that is what the Startup Disk preference panel does already. I know exactly what Systems I have on my computer and wanted a way to point them out quickly and easily.
Below is an example of the final version I am using (incorporating other posters suggestions as well as my own). A few things... I removed references to Finder because I call the script from the "Script Menu" menu extra and see no reason why the Finder should be brought forward. I prefer to pop up the dialog over whatever app I am currently using. Also, for simplicity and brevity, I set it up using only 2 system folders (even though I have 4). I think it should be obvious how to add more System choices if you like, but if it's not clear let me know. I also used my OS X and OS 9 folders on the same partition to avoid having Volume Name references in the script. Again, you will have to customize the paths to your System Folders and add additional passes through each routine if you have more than 2 system folder choices. Just wanted something short I could post to show all of the features I incorporated. This script will tell you what system you are currently set to boot from and ask if you would like to change. You are given a button for each choice. If you are currently set to boot into X, then the default button will be 9. If you are currently set for 9 then the default button will be X. Click a button (or hit return to pick default) and that's it. My apologies that I have not commented the various routines but I wanted to get this done and posted in a hurry. Of course, this also means I may have missed something. Feedback is appreciated if I have left out or overlooked anything discussed above (before too many people rely on my mistakes!!) Code:
do shell script "/usr/sbin/bless -info / | grep -c 'Blessed System Folder is /System/Library/CoreServices';echo $output"BTW, I have added my other systems back in and all still works fine. I now have the options of 9.2.2, 9.1, 10.1.2, or 10.1.3. You just have to decide what criteria you want for determining the default button. I alternate between the two I boot into most (9.2.2 and 10.1.3) Finally, bless does not seems to work with a System Folder prior to 9.1 (i.e. 9.0.4). If anyone can get that to work, let me know. |
I am getting a little confused with all the posts! :) I do plan to use Classic, more often even than the OS 9 mode. OS X 10.1.3 is my default OS. Which script is the best one for me to use?
|
Quote:
Having said that, if you have a simple two OS system (with 10.1.3 and 9.2.2 on the same partition) you can probably use my script posted just above without alteration (aside from substituting your actual admin PW in the two places it currently says "AdminPassword". Any variation from that basic setup will require customizing the paths to your system folders, the text indicating OS names (e.g. change 9.2.2. to 9.1 if that is what you are running), and so forth. Because I wanted my script to be as descriptive as possible, while also keeping it brief, it requires customization. There are ways to write this that require no customization (i.e. have the script find your System folders for you, and have the script determine the version of those system folders) but that kind of robust functionality already exists in the Startup Disk control panel. My goal is to create a streamlined version that savrifices automated functionality for speed. You have to pick the version that does what you want done (based on our descriptions, or based on trying them out). I don't know if any of the others are fully useable yet since I haven't tried them -- just been working on my own. |
Maclaw: Good point. The script I wrote almost does exactly what the Startup Disk pane does!:eek: My script is a bit quicker and requires fewer clicks, though. This is on my G4 450DP with only 3 partitions, so I imagine it will slow down quite a bit on slower systems with more disks/partitions. I would like to point out that telling the Finder to do something doesn't bring it to the front unless there is an activate in there.
Meancode: I'm glad to see you are discovering the joys of scripting. That code snippet only appears to work on a single partition (or maybe my system is being flakey). I'm looking to get the path of the folder, not just a true/false, though. I noticed that this wasn't metioned yet, so here goes: The Startup Disk pane can be accessed more quickly if /System/Library/PreferencePanes/StartupDisk.prefPane is put in the dock. I think I saw something similar on my other favorite site once. |
I use OS 9 mode for Virtual PC and Norton Utilities/AntiVirus but everything else runs in OS X native or Classic. Thanks for the script; I will give it a try.
Regarding the tip posted at http://www.macosxhints.com/article.p...10416184548354 I used the following script to try to reboot from OS 9 to X and got the following error when trying to check syntax: A application constant or consideration can't go after this application constant or consideration. "Startup system folder" was highlighted when the error came up. tell application "Startup Disk" activate set startup system folder alias to alias "Macintosh HD:System:Library:CoreServices:BootX" quit end tell tell application "Finder" restart end tell |
A security hole in this method
The procedure of many answers to the question of how to restart automatically OS X in OS 9 using a AppleScript, can have a security hole, provided you have multiple users in your computer. If you bless the system 9 folder with a run-only script with contains the administrator password and other users can start this script (not to read it), then they have access to all the information of the computer after restart, because OS 9 loses the folder privileges.
If this scenario is a problem, there are several solutions: 1) Set the privileges of the script for use of the administrator only. 2) Store the script in a reserved folder. 3) Do not store the password in the script. I am waiting for your answers. Jaime. |
| 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.