Quitting an app within SheepShaver ...

Hi,

I need previous accounting data created in OS 9, so I use the SheepShaver emulator on my Intel machine … It’s a great all-in-one solution.

I am not a programmer neither a technical expert, so my vocabulary can be misleading. I use SheepShaver from within Classic-On-Intel. It seems to be a little «app» that launches SheepShaver with a specific prefigured configuration. When Classic-On-Intel is launched, it launches a process nested inside Classic-On-Intel called COI.

Concretely on my desktop computer, I see:

¢ an icon in my dock named COI
¢ a SheepShaver OS X application menubar and a window named SheepShaver
¢ inside that SheepShaver window lives OS 9 and my OS 9 application named Simply Accounting (SA)

I am trying to quit SA and SheepShaver by script. I don’t know how to speak to SA that lives inside COI. I tried with this little script to quit COI, but I need to press the return key and it doesn’t work. This is the script:

quit application "COI"
tell application "System Events"
	keystroke (ASCII character 3)
end tell

In the AppleScript Editor I get this response:

tell application "COI"
	quit
		--> error number 0
end tell
tell application "System Events"
	ASCII character 3
		--> error number -10004
end tell
tell current application
	ASCII character 3
		--> ""
end tell
tell application "System Events"
	keystroke ""
end tell

I tried to understand what’s happening … and I have to admit that I don’t ! First, I do I quit SA ? When done, to quit COI, I need to press the return key. How do I do that ? Maybe somebody has a clue …

Regards.

Robert Lespérance
Québec, Canada

rlesperance:

I’m not set up to answer your question with any precision. I just bought an Intel MacBook Pro, but it’s still in the box. I expect to be trying SheepShaver (in some form) when I get around to setting up the MBP. (My PB G4 is serving me just fine for the moment.)

However, you may need to change some of your syntax and be absolutely sure you’re using the correct app and/or process names of your target apps.

Here’s the basic ‘tell process’ format:



tell application "TextEdit" to activate

tell application "System Events"
	tell process "TextEdit"
		--keystroke "n" using command down -- open new document
		keystroke (ASCII character 3)
	end tell
end tell


You’re right, in some instances, you don’t need to tell the process explicitly, but…

Given that SheepShaver and the COI distribution of it are rather odd ducks, you may not be able to address them with AppleScript at all. You may need to kill the process(es) with a shell script… something else I can’t help with. But if all you’re trying to do is quit them, there pretty much has to be a way.

How do you normally ‘quit’ COI/SheepShaver? Is it effectively the same thing as shutting down the (Classic) OS?

I’m curious why you went with the ‘Classic-On-Intel’ version, and not just SheepShaver. Does it work well? In time, I’m likely to be in the same circumstances as you and wanting to (try to) script within SheepShaver. I assume you can run scripts compiled under the Classic Script Editor just fine, yes? I wonder if you can trigger them from outside the SheepShaver ‘envelope’.

Peter B.


Hi Peter,

I have not tried SheepShaver extensively, but any attemp with any version of SheepShaver resulted in funny problems. I was either unable to display a large view of the window, or if enlarged, it was distorted and the display was not at a good resolution. Also, the mouse cursor is doubled and it display 2 arrows … I was also unable to move data between OS 9 and OS X. Maybe all these are now resolve but when I tried COI I got immediate stability and all those problems were corrected, except for printing to local USB printer, that I resolved by printinf to PDF and using a folder script.

Also, I found complicated all the explanations of the E-Maculation forum. Some important informations were not updated and so many version were available and contradictory … So when I found and first used COI, I got a simple solution, all files requiered were there and it worked easy and fast, out of the box, I would say.

For now, I am using an old OS 9 accounting software and it just work perfectly. It was just on time, because my old PPC iMac died in the same week. So I can now continue my accounting work.

When I will have time, I will give the latest version of SheepShaver a try. I will compare the stability and the features more extensively between the 2.

As for my problem … The quit instruction of my script get’s through COI because the final closing window appears with choices to be selected. A return ke would do the job. That’s why the instructions below gets in:

tell application "System Events"
   keystroke (ASCII character 3)
end tell

This instruction does not go through and the message display just stays there waiting, meaning that the Return key has no effect. That is for the first item. For the second, I would like to quit my OS 9 accounting app before shutting down the COI engine and I don’t know how to do that either by AppleScript of shell scripting.

So hoping this will help you with SheepShaver … I am so glad that I have found it and to see how speedy and stable it is.

Regards.

rlesperance:

Thank you very much for the description of COI… it sounds well worth trying… perhaps first.

I still think the ‘tell process’ method might be worth a try, even if it seems less direct than ‘tell System Events’. It would also be (very much) worth knowing whether you can get the envelope process to execute more complex keystrokes. If you can ‘keystroke “q” using command down’ (for example), you may be able to quit the accounting program if it’s frontmost.

The parent process name may or may not be the same as the app name… you should be able to find it by way of elimination (and intuition) in Activity Monitor.

I have a key macro utility (KeyQuencer) that I still use for some things in Classic, though mostly I rely on keyboard commands (FastScripts) in OS X now. However, if KeyQuencer could be invoked from outside the COI envelope, most any Classic scripting would still be possible.

If it were a simple matter, I’d unpack the MBP and download COI and give it a try… but because of my low speed (24K) connection, I must go to the library for their broadband to download.

Soon, perhaps… not today.

Thanks Again… and keep trying… I’ll be very curious if you can get something(s) to work.

Peter B.


Robert:

It occurred to me that you have been trying to get your script:


quit application "COI"
tell application "System Events"
   keystroke (ASCII character 3)
end tell

… to work from the Script Editor. It definitely won’t. Script Editor will (likely) have the focus once the quit dialog has been dismissed ‘manually’… and receive the keystroked return.

After doing some experimentation trying to script quit TextEdit (with an open document), then executing a ‘keystroke return’ command within the same script, it won’t do the keystroke even when the script is invoked from a keyboard macro… (which leaves the focus on TextEdit).

So if the TextEdit example is a valid one, and comparable to your situation, it doesn’t look like you can combine the quit and the keystroke return. You can dismiss the dialog with a keystroke invoked from a keyboard command… if that alone is any use.

It is apparently the quit dialog that ‘jams’ everything up.

Here is a possible GUI workaround for you that I ‘discovered’ after trying a lot of other things:


tell application "COI" to activate

tell application "System Events"
    tell process "COI"
        keystroke "q" using command down
        keystroke (ASCII character 3)
    end tell
end tell

Again, the name may be different than the app name.

Please let me know if it works. If it does, it may be of great use to me when I ‘get to’ SheepShaver.

Thanks.

Peter B.


Robert:

Sorry to be hijacking your thread, but I had some additional thoughts about the script ‘situation’ presented by SheepShaver. I also reread your first post and now see that the app menu belongs to SheepShaver… not Classic-On-Intel.

Obviously, I don’t yet know their inter-relationship…

Is COI basically a background application? Does it have any menus? Does the SheepShaver menu have standard commands (i.e. hide, quit, etc.)? Are there keyboard shortcuts for those commands?

Are you sure quitting COI is the appropriate thing to do rather than quitting SheepShaver? Do both COI and SheepShaver show as processes in the Activity Monitor?

On the basis of your answers, I may be able to tell you whether it’s going to be possible to script a whole host of things in SheepShaver… or just start up and quit.

As an additional experiment, you might try substituting “SheepShaver” for “COI” in the quit script above and see what happens.

If the ‘parent’ or envelope process can receive key commands via GUI from the OS X ‘side’, there is probably no end to the scripting possibilities… provided one has a key macro program that runs in Classic.

This is exciting for me because - as of this moment - many of my most used apps are Classic apps - email, word processing, photo editing, FTP… and I even break out BBEdit sometimes to do things TextEdit can’t.

I deliberately put off moving to Intel in 2006 when I bought one of the last PowerBooks available… but I can only keep it alive so long.

Thanks for any more information you can provide… it’s very much appreciated.

Peter B.


Peter,

It is a little bit complicated for me to explain … but I will give it a try. As I understand it, Classic-On-intel+ (COI+) is like a «shell» that contains a pre-configured SheepShaver version. I downloaded the original package of COI+ from this link:

http://homepage.mac.com/jlg/COIV4.0.1.zip.

You will find more explanation about it, on the January 5th 2009 post at this page:

http://macwindows.com/OS9_on_Intel_Mac.html#092408b

The SheepShaver app is activated by double clicking the Classic item that you will find at the first level of the folder. If you control + click the Classic item, it will reveal somewhere inside an item named COI and, deeper, what seems to be an Unix item called SheepShaver.

I would suggest that you try this yourself. I am a liitle bit confused, and not sure what all this is about. My explanations could get you mislead. In any advent, when I double click the Classic item, it opens a window named SheepShaver that has a complete menu bar and a Quit menu item, like you asked. That’s the emuator window.

In Activity Monitor, a process called SheepShaver appears, but no AppleScript will have it quit. The only way I got it to quit was by invoking the COI process hidden in the Classic item. That’s the reason my script refers to COI.

I would suggest that you give it a try, and maybe we could begin from there. I wish we could continue this discussion in a forum dedicated to COI+, but it doesn’t seem to exist. E-Maculation’s forum focuses only on the SheepShaver application. But because I found it so reliable and fast, that I didn’t bother yet trying SheepShaver.

Regards.

Robert Lespérance
Québec, Canada

P.S. Do you know how to hide a link behind a word in this forum ?

Robert:

This is making me impatient to try what we have been talking about, but again, for me that may be days away.

Could you please try these scripts (as amended from above)?

They may answer some questions for both of us.


tell application "COI" to activate

tell application "System Events"
tell process "COI"
keystroke "q" using command down
keystroke (ASCII character 3)
end tell
end tell


tell application "SheepShaver" to activate

tell application "System Events"
tell process "SheepShaver"
keystroke "q" using command down
keystroke (ASCII character 3)
end tell
end tell

If you could let me know what happens with each, I would appreciate it… and you may be ‘off the hook’ for the moment.

Thanks Again.

Peter B.


Eureka … You almost got it ! The script with SheepShaver does not work. This version works:

tell application "System Events" to exists process "SheepShaver" -- execute only if SheepShaver is running (COI does not show in Activity Monitor, but SheepShaver does ...)
tell application "COI" to activate -- brings the COI/SheepShaver window to the frontmost position

tell application "System Events"
	--tell process "COI" -- no effect
	keystroke (ASCII character 27) -- triggers the cancel button to close any open selection window
	keystroke "q" using command down -- saves any open document and quits my accounting software
	do shell script "/bin/sleep 1" -- delay needed for the next step to execute adequately (seems to be to fast ??)
	quit application "COI" --  quits COI/SheepShaver and displays closing options
	do shell script "/bin/sleep 1" -- delay needed for the next step to execute adequately (seems to be to fast ??)
	keystroke (ASCII character 3) -- triggers the return button in the closing options of COI/SheepShaver
	--end tell
end tell

Thanks for helping. Regards.

Robert

“From the mouths of babes…”

Robert:

You (clearly) knew far more than you were letting on. I’m surprised I had anything to offer that was of any use to you.

I have saved this thread in the hopes it may be of use in future.

If you see a post enquiring about SheepShaver scripting not too long from now, I hope you’ll be kind enough to reply… as it will likely be me doing the asking.

Thanks.

Peter B.

PS - (off topic) I ventured to Quebec as long ago as 1974… and believed it to be (then) one of the most beautiful cities I had visited in North America. I hope it has not changed such an awful lot. I wish I could afford a night in the Chateau Frontenac.


Peter …

I am really not a pro. I venture around and try a lot to find solutions to my problems.

For your information, Québec city is as nice as it was. Have a look on the Chateau Frontenac web site and you will probably find very interesting offers and rebate in low season. I have been there with my wife last fall for a very reasonable price.

Never stop coming in Québec … it has so much to offer: Charlevoix, Gaspésie …

If you open another thread about SheepShaver, just post a line in this thread and I will know …