Login  •  Register


The time is now: Fri Dec 15, 2017 6:25 am

Emaculation wiki  •  Delete all board cookies



Post new topic  Reply to topic Page 1 of 1 [ 7 posts ]
Print view Previous topic  |  Next topic
Author Message
PostPosted: Mon Jan 18, 2010 5:49 pm 
Offline
Forum All-Star

Joined: Tue Oct 14, 2008 12:12 am
Posts: 801
There are times when I want to run only a single program in SheepShaver or Basilisk II. Here's an AppleScript that can be put into the Startup Items folder in the System Folder in a SS/BII system and it will do this:

When the emulator starts up, the script will launch the application you specify in the script. When you close the application, the emulator will shut down. The first time you run it, but only the first time, it will ask you where the application is located.

To create this script, copy the code below into the AppleScript editor (you may need to install it separately) inside the SheepShaver/Basilisk II system. When saving, set Kind to Application; add checkmarks next to "Stay Open" and "Never Show Startup Screen."

Test it by launching it OUTSIDE the Startup Items folder before actually putting it in the Startup Items folder.

This works in System 7.55 or later. I know there are more efficient ways of writing it, but the more efficient ways don't seem to work in ancient Macs. (For example, "delay" doesn't exist in system 7.5.5, so I used a kludge workaround instead.)

One important thing: Make absolutely certain that the application name specified in two parts of the script is exactly the same as the name of the application itself. If the two names don't match, then the script will simply shutdown SheepShaver or Basilisk II after a few seconds.

I've tried using a variable for the application name, but that doesn't seem to work, at least not on 7.55.

Code:
global appRunning
global cycles

on run
   tell application "APPLICATION NAME HERE" to activate
   set cycles to 1
end run

on idle
   tell application "Finder"
      tell application "Finder" to name of processes
      if the result contains "APPLICATION NAME HERE" then
         set appRunning to true
      else
         set appRunning to false
      end if
   end tell
   if appRunning is false then
      if cycles is greater than 1 then
         -- tell me to quit -- use this for testing to avoid shutdown
         tell application "Finder" to shut down
      end if
   end if
   set cycles to cycles + 1
   return 5 -- number of seconds between tests for application running
end idle


Top
 Profile  
Reply with quote Post a reply  
 Post subject:
PostPosted: Mon Jan 18, 2010 8:07 pm 
Offline
Expert User
User avatar

Joined: Thu Feb 09, 2006 10:24 pm
Posts: 4869
Location: Amsterdam, Netherlands
The usual way to this is to put an alias of the application in the Startup Items folder in the System Folder, no script needed. At startup the application will launch. And shutting down the emulated machine will of course also quit the application, seems to me just a simple as making the emulated machine shut down by quitting the application.


Top
 Profile  
Reply with quote Post a reply  
 Post subject:
PostPosted: Mon Jan 18, 2010 8:53 pm 
Offline
Forum All-Star

Joined: Tue Oct 14, 2008 12:12 am
Posts: 801
Yes, I see - that is MUCH simpler. There is no real advantage to this script method except (maybe) this very small one: if you close the application first, you don't have to close down the system itself, because the system closes automatically. You can save exactly two mouse clicks by my method, so I probably spent a million times more effort writing the script that I can ever save by using my script...!


Top
 Profile  
Reply with quote Post a reply  
 Post subject:
PostPosted: Mon Jan 18, 2010 10:57 pm 
Offline
Expert User
User avatar

Joined: Thu Feb 09, 2006 10:24 pm
Posts: 4869
Location: Amsterdam, Netherlands
emendelson wrote:
I probably spent a million times more effort writing the script that I can ever save by using my script...!

Well, it was a good exercise in writing AppleScript. :wink:


Top
 Profile  
Reply with quote Post a reply  
 Post subject:
PostPosted: Mon Jan 25, 2010 10:10 am 
Offline
Space Cadet

Joined: Sun Jan 24, 2010 2:00 am
Posts: 5
This is actually quite useful, thanks emendelson. Though for the application I was doing this with it seemed no delay was necessary (either on 7.6.1 or 9.0.4), so with an alias to the app in startup items it turned out all I needed was this:
Code:
on idle
    tell application "Finder" to if (count of processes) is 1 then shut down
    return 2 -- the code is so much shorter I figure it won't hurt to run it more often
end idle


If you do need a delay though, you could try putting a repeat in the run handler to do something silly for a while.


Top
 Profile  
Reply with quote Post a reply  
 Post subject:
PostPosted: Tue Jan 26, 2010 1:01 am 
Offline
Forum All-Star

Joined: Tue Oct 14, 2008 12:12 am
Posts: 801
Gannet wrote:
This is actually quite useful, thanks emendelson. Though for the application I was doing this with it seemed no delay was necessary (either on 7.6.1 or 9.0.4), so with an alias to the app in startup items it turned out all I needed was this:
Code:
on idle
    tell application "Finder" to if (count of processes) is 1 then shut down
    return 2 -- the code is so much shorter I figure it won't hurt to run it more often
end idle


If you do need a delay though, you could try putting a repeat in the run handler to do something silly for a while.


Very elegant! Unfortunately, it produces an error message in 7.5.5 - "the result of a numeric operation was too large". I think AppleScript improved a lot between 7.5.5 and 7.6.1...


Top
 Profile  
Reply with quote Post a reply  
PostPosted: Tue Jan 24, 2017 11:44 am 
Offline
Student Driver
User avatar

Joined: Tue Jan 24, 2017 6:58 am
Posts: 10
Thanks for writing this!

I was working basically the same script until I found this.

As you say, you can put something in startup items, but you have to shut down the OS to exit the emulator. Requires a script to get the OS to shut down when the application is exited.


Top
 Profile  
Reply with quote Post a reply  
Display posts from previous:  Sort by  
Post new topic  Reply to topic Page 1 of 1 [ 7 posts ]


Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
 

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group