quit AS Studio App without closing child processes

I have an app that manipulates a preference file and then launches the app for which the preferences exist. When I quit the script, I want the clent app (game) to stay up, but my ASStudio app to go away. Right now it quits after my client app quits. If I tell AS to ignore application output turned on, it immediately shuts down my target after it started.


		try
			tell window 0
				set visible to false
			end tell
			if theGame is 1 then
			tell application IsolaOneAppName
					activate
					-- If it can't find it, it should ask...
				end tell
			else if theGame is 2 then
				tell application IsolaTwoAppName
					activate
					-- If it can't find it, it should ask...
				end tell
			end if
			
		end try
		quit
	

My current solution is to make my main window invisible, but that’s hardly what I want.

Hi MCroft,

If I understand you correctly you have two ASS applications; one an application that sets the preferences for the second (“prefmaker”), the other one a game (“game”)? Is the prefmaker supposed to also launch the game? Or is the game supposed to launch the prefmaker?

Hi, thanks for responding.

That’s close. the game isn’t my app, it’s a commercial release from a small developer (actually it’s two different ones, which explains the if statements).

The game has some behavior that isn’t ideal on startup for multiple users who don’t use different accounts on the machine (not what I’d do, but the problem is real for at least some users). My script edits the game’s binary prefs file and lets the user pick which game slot to start in on startup.

Once I do that, I want to launch his game and then go away and my two tries lead to the behavior described.

Any ideas?

Hmm… my idea would be to launch the game using a shell script command:


	if theGame is 1 then
		do shell script "open -a /path/to/IsolaOneAppName.app"
	else if theGame is 2 then
		do shell script "open -a /path/to/IsolaTwoAppName.app"
	end if
 

The “do shell script” will return immediately after launching the app, allowing you to properly quit the ASS app.

Model: Intel iMac 20"
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi Dan,

I tried pursing that, but I can’t figure out a way to locate the /path/to/the/app.
The tale of woe: the app is a commercial game which the various game distribution sites wrap in their favored DRM and possibly rename completely. Users can, of course, put it anywhere. There’s no creator code and for all of the IsolaOne, the Bundle Identifier was shipped as “com.apple.MyCarbonApp”. For Isloa2, some but not all use “com.ldw.Isola2”. Others use com.apple.MyCarbonApp. It may not be entirely his fault, as they’re doing the wrapping. More than half my code is to deal with the various appname/prefsfilename combos that I know about. I can’t launch it and ask it where it is, either, because I need to change the prefs file before the game starts (that’s the point of the app) and there’s no silent mode.

I know the finder can find the app when I tell it “open IsolaOneAppName”, but I haven’t figured out a way to get the path to it without opening it.

The developer isn’t happy about that, and I’m less so, but the reality is that’s what I’m trying to enhance with my AS Studio app.

I tried doing a do shells script “find /Applications -name Isola.app”, but that took 15 seconds to return on my machine and didn’t get all the right answers.

Hey MCroft,

sorry, been away over the weekend and had a busy time today… anyway, regarding your problem #1, actually identifying the application and the prefs file for it: How about something like this:


set pathToIsola to (do shell script "mdfind \"kMDItemContentType == 'com.apple.application-bundle' && kMDItemFSName == '*isola*'"\")

The mdfind command will use spotlight for searching any application-bundle whose name is like isola. When I ran the above query for kMDItemFSName = ‘iChat’ it took about 4 seconds on my Intel iMac (OS 10.4.9, 2.0 GHz, stock 250 GB HD). The possible issue here (you’ll have to say whether it is an issue indeed) is that this will work only as long as the app resides on a HDD that is indexed by spotlight.

From here on I would suggest to use /usr/bin/defaults:


--property keyToChange: "somekeyname"
--property newValue: "someValue"
do shell script "/usr/bin/defaults write -app '" & pathToIsola & "' keyToChange newValue"

What do you say, so far so good? :wink:

Best,
danB

Model: Intel iMac 20"
Browser: Safari 419.3
Operating System: Mac OS X (10.4)