Login  •  Register


The time is now: Fri Apr 19, 2019 12:45 pm

Emaculation wiki  •  Delete all board cookies



Post new topic  Reply to topic Page 1 of 1 [ 13 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: 1013
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: 5353
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: 1013
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: 5353
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: 1013
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
Inquisitive Elf
User avatar

Joined: Tue Jan 24, 2017 6:58 am
Posts: 27
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  
PostPosted: Sat Jan 05, 2019 9:17 pm 
Offline
Inquisitive Elf
User avatar

Joined: Tue Jan 24, 2017 6:58 am
Posts: 27
Here is the solution:
Code:
tell application "Finder"
   open file "Macintosh HD:ApplicationName"
   shut down
end tell


If the application is launched as a file with finder, the finder will issue the shut down command once that application is quit.


Top
 Profile  
Reply with quote Post a reply  
PostPosted: Sun Jan 06, 2019 4:47 am 
Offline
Forum All-Star
User avatar

Joined: Fri Nov 27, 2009 5:11 am
Posts: 2518
Location: Emaculation.com
We need this on the wiki somewhere; I keep on arriving at this solution every 4 years or so. Then I forget about it.


Top
 Profile  
Reply with quote Post a reply  
PostPosted: Sun Jan 06, 2019 11:12 pm 
Offline
Inquisitive Elf
User avatar

Joined: Tue Jan 24, 2017 6:58 am
Posts: 27
It's not a hugely reliable solution though. Sometimes shut down doesn't work for who knows what reason. It's much better to replace the Finder with the application. It also boots faster and prevents Finder or the user from messing with the OS and destabilizing the wrapped program. But that doesn't cause the OS to shut down after the application is quit so the user gets stuck.

I've been working on a Finder replacement in C++/MPW called "WrapperFinder" that actually issues direct commands to Toolbox to launch the application and then force a (usually clean) shutdown after the application has been quit. You should be able to specify the absolute path of the application in a Finder.cfg file in the System Folder- as using an alias in Startup Items is notoriously unreliable.

So far, it's fully functional when using ToolServer and an MPW StartupTS script as a Finder replacement. ToolServer has some lag and weirdnesses as it loads up all of the MPW interfaces before executing the script, and it can't be used as a library in an application (if anyone knows otherwise, you would save me so much time). But it still works WAY better than using an AppleScript. Right now I'm implementing the Apple Events manually in C++. Shut Down works, but the LaunchApplication API in Process Manager is taking some time to implement. LaunchApplication is a nightmare of hierarchical structs and pointers. It will definitely work though (if it works in MPW shell you can always implement it in C++).

Another thing that will help with reliability is to make the OS drive read-only and put the application in a separate drive. I haven't tried that yet, but I'll get there. I'm guessing OS9 will yell at me for it and it will break stuff.


Top
 Profile  
Reply with quote Post a reply  
PostPosted: Mon Jan 07, 2019 4:22 am 
Offline
Inquisitive Elf
User avatar

Joined: Tue Jan 24, 2017 6:58 am
Posts: 27
adespoton wrote:
We need this on the wiki somewhere; I keep on arriving at this solution every 4 years or so. Then I forget about it.


Actually, I'd love to add this to the wiki under the "misc" section if anyone is interested. I'll talk to the necessary parties whenever I change anything. But there are a definitely a number of things I could contribute if you're interested.

No worries if you can't though.


Top
 Profile  
Reply with quote Post a reply  
PostPosted: Mon Jan 07, 2019 5:49 pm 
Offline
Forum All-Star
User avatar

Joined: Fri Nov 27, 2009 5:11 am
Posts: 2518
Location: Emaculation.com
I'm interested in the FinderWrapper application; I keep meaning to build one of those or find one I used to use in the System 6 days, but it would take me too long to get my toolchain set back up and my head in the right space. So I'm more than happy to use yours :)

Eventually, I'd like to create an app that you can drag a Classic application onto, and it'll automatically set it up to auto-boot/shut down in a wrapper app -- kind of like Boxer does for DOS software.


Top
 Profile  
Reply with quote Post a reply  
PostPosted: Tue Feb 05, 2019 5:01 pm 
Offline
Tinkerer

Joined: Sun Nov 05, 2006 1:21 am
Posts: 63
Nice custom solution that a lot of people have found useful. Thank you.

Where you say it's important to specify the application by exact name: you can get the name of an app on a given machine from its four-character file creator. For example, the creator of WP Mac is "WPC2". While a user can name an app anything, its file creator doesn't change. So:

Code:
tell application "Finder" to get name of application file id "WPC2"


--> "WordPerfect" on my machine.

This works on OSX as well if the app in question has a creator type; not all do any more.

John R.


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


Who is online

Users browsing this forum: Google [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:  
Powered by phpBB® Forum Software © phpBB Group