OS X/macOS - detect when SheepShaver shows "?" icon?

About SheepShaver, a PPC Mac emulator for Windows, MacOS X, and Linux that can run System 7.5.3 to MacOS 9.0.4.

Moderators: Cat_7, Ronald P. Regensburg, ClockWise

Post Reply
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

OS X/macOS - detect when SheepShaver shows "?" icon?

Post by emendelson »

I've been working on an AppleScript application that launches SheepShaver. If SheepShaver starts up and displays the question-mark icon, I'd like to be able to detect this and kill SheepShaver, notifying the user what has happened.

Is there any way to accomplish this? I don't see anything in the Console that might report when SheepShaver didn't open a disk file.

Thanks for any suggestions.
User avatar
adespoton
Forum All-Star
Posts: 4227
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by adespoton »

lsof will tell you which files and handles are opened. You could check and see if the open handles differ between the ? state and a loading state....
User avatar
Cat_7
Expert User
Posts: 6145
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by Cat_7 »

When does the blinking question mark happen?
-When no boot file is found
-When a boot file is found, but it is defective (i.e. not blessed correctly)

Simple solution might be to check whether the designated boot file hasn't been accessed for, say, the last 4 seconds in a 5 second period from start?

Best,
cat_7
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by emendelson »

Cat_7 wrote:When does the blinking question mark happen?
-When no boot file is found
-When a boot file is found, but it is defective (i.e. not blessed correctly)

Simple solution might be to check whether the designated boot file hasn't been accessed for, say, the last 4 seconds in a 5 second period from start?
I should have explained further. I've been modifying my "Mac OS 9" application (an AppleScript that contains a copy of SheepShaver and a disk image) so that multiple users can run it from the Applications folder.

This works smoothly if one user starts the application, runs it, and then shuts it down before another user starts up the same application. However, if one user starts the application, and then a second user also tries to run the application, SheepShaver displays the question mark icon to the second user.

I've tried to find ways to detect whether SheepShaver is already running in a process owned by the first user, so that I could warn the second user and not start SheepShaver at all, but nothing I've tried has worked. (I probably haven't looked hard enough.) So I thought the simplest way might be to detect the question mark icon. Either way would get the job done: either detect the other user's process before launching SheepShaver or detect the question mark icon and shut down the new instance of SheepShaver.

I've already tried testing whether the disk image is writable when another user is accessing it via SheepShaver, but OS X/macOS always reports that the image is writable. I've tried various forms of the "ps" shell command, but i haven't found anything that solves the problem.
User avatar
Cat_7
Expert User
Posts: 6145
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by Cat_7 »

Then adespoton's tip might work: see whether the file is already open.

Best,
Cat_7
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by emendelson »

Thanks for that, but lsof is one the many things I've already tried. It doesn't report files opened by another user unless you use sudo, and that isn't practical for ordinary use.

I'll be grateful for any other ideas!
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by emendelson »

OK, I solved this by writing this script to detect whether the current user or another user is running SheepShaver. It's a terrible kludge, but it seems to work. (What's missing is a test whether the other user's SheepShaver is the same copy as the local user's.)

Code: Select all

set myName to do shell script "whoami"
set allNames to do shell script "users"
set listNames to my stringSplit(allNames, " ")
set deleteMe to {myName}
set otherNames to {}

repeat with i from 1 to count listNames
	if {listNames's item i} is not in deleteMe then set otherNames's end to listNames's item i
end repeat

set activeOther to false
repeat with i from 1 to count otherNames
	set appFound to do shell script "ps -U" & space & otherNames's item i & space & "| grep SheepShaver | grep psn | awk '{print $1}'"
	if appFound is not "" then set activeOther to true
end repeat

set activeHere to false
if application "SheepShaver" is running then set activeHere to true

set otherString to "being run by another user"
if activeOther is false then set otherString to "NOT" & space & otherString

set localString to "being run by you," & space & myName
if activeHere is false then set localString to "NOT" & space & localString

tell me to activate
display dialog "SheepShaver:" & return & return & "is" & space & otherString & return & return & "is" & space & localString buttons {"OK"}

on stringSplit(theString, theDelimiter)
	set oldDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	set theArray to every text item of theString
	set AppleScript's text item delimiters to oldDelimiters
	return theArray
end stringSplit
User avatar
Ronald P. Regensburg
Expert User
Posts: 7821
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by Ronald P. Regensburg »

Just wondering:
You want different users use the same startup volume, though not at the same time. Using the volume will make changes to that volume. Imagine: User 1 uses SheepShaver and quits. Then user 2 uses SheepShaver and quits. Then again user 1 uses SheepShaver. Wouldn't user 1 be confused by changes made by user 2?
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by emendelson »

Ronald P. Regensburg wrote:Just wondering:
You want different users use the same startup volume, though not at the same time. Using the volume will make changes to that volume. Imagine: User 1 uses SheepShaver and quits. Then user 2 uses SheepShaver and quits. Then again user 1 uses SheepShaver. Wouldn't user 1 be confused by changes made by user 2?
Yes, that could be confusing. Of course each user could install the a separate copy of the app in his or her home folder somewhere, and then they would never get in each other's way. I'll leave it as it stands for now, because I made the change only in response to the thread about Chubby Bunny and permissions, and this at least gets things started.

One possibility is to share a startup volume and have each user have his or her own data volume, which only gets mounted when that user launches the application. But that's a job for another time.
User avatar
Ronald P. Regensburg
Expert User
Posts: 7821
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by Ronald P. Regensburg »

emendelson wrote:One possibility is to share a startup volume and have each user have his or her own data volume, which only gets mounted when that user launches the application. But that's a job for another time.
Unless the startup volume is locked, changes will be made to the System Folder, certainly to preferences settings and control panel settings. Software installations could add new extensions or control panels. Experienced users may disable/enable extensions and control panels, or add/remove startup items.
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by emendelson »

Probably what I should do in a multiuser system is (1) lock the system disk and (2) create a new data disk for each user who starts the system, and store it in the user's Application Support folder (testing for its existence at startup). This wouldn't be hard, presumably.
User avatar
Ronald P. Regensburg
Expert User
Posts: 7821
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by Ronald P. Regensburg »

That setup will prevent proper installation of software that installs files in the System Folder. It may work otherwise.

Wouldn't it be much simpler when each user has his/her own copy of the whole package? Why does it need to be shared?
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by emendelson »

Ronald P. Regensburg wrote:That setup will prevent proper installation of software that installs files in the System Folder. It may work otherwise.

Wouldn't it be much simpler when each user has his/her own copy of the whole package? Why does it need to be shared?
It doesn't have to be shared. I was trying to work out a way to accomplish what someone was trying to solve with Chubby Bunny in another thread. This is mostly an intellectual exercise - a way of learning AppleScript. I'll go back to the single-user model.
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by emendelson »

Ronald P. Regensburg wrote:Unless the startup volume is locked, changes will be made to the System Folder, certainly to preferences settings and control panel settings. Software installations could add new extensions or control panels. Experienced users may disable/enable extensions and control panels, or add/remove startup items.
Wait - I forgot that OS 9 under SheepShaver supports the Multiple User feature. This means that a SheepShaver-based app can be in the application folder, with only one disk image, and each user can log in separately to OS 9, just as they did with real multi-user systems in the OS 8/9 era.

As you say, it's simpler for each user to have his or her own copy of the application, but a multi-user system is certainly feasible.
User avatar
sentient06
Mac Mechanic
Posts: 188
Joined: Tue Mar 29, 2011 8:57 pm
Location: London, UK

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by sentient06 »

Medusa can kill SS. It doesn't detect it, of course. It is open-source, so feel free to fork it.
User avatar
adespoton
Forum All-Star
Posts: 4227
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by adespoton »

One other option here, although it might make things too complex for the use case:

Modern disk images have the ability to enable shadow copies. So you could have a separate shadow copy for each user, adding the username into the shadow copy filename. That way, you have one base image, but the changes each user makes go into their own shadow copy. That way, you have something distributable, but each user gets their own data set.

Would that help?
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: OS X/macOS - detect when SheepShaver shows "?" icon?

Post by emendelson »

Updates on this system are now in a more appropriate thread:

http://www.emaculation.com/forum/viewto ... =33&t=9358

Briefly: I rewrote the application so that it works for multiple users without any effort. Each user can (optionally) create a non-booting disk image that will only be visible when that user is running the application (it's stored in the user's ~/Library/Application Support folder). If an administrator wants to set it the system as a multi-user OS 9 system, that admin is free to do so. Otherwise, it works exactly the way a real OS 9 Mac would work if it were accessible to more than one user.

However, I hope you will spell out exactly how your suggestion could be put into effect - with full details of the exact commands involved, how to set up permissions, etc. This could be very useful for anyone else who works with SheepShaver. Without the full details that you can provide, probably no one will have any real idea of how to put your idea to use, and people might waste many hours trying various things that won't work. You could prevent this by providing real, practical, tested details. Thank you in advance for any information!
Post Reply