open apps in the background

Hi,

the shell script "open -g "& quoted form of posix_path_to_app
does not work like expected.

Hello.

The command below works from a terminal window.

And this works from an AppleScript

do shell script "open -ga /Applications/VLC.app"

It all depends on how you interpret “background” here “background” means “not frontmost”. :wink:

Hi
thanks for the clear explanation.
Unfortunately, “g” or “ga” doesn’t work on my machine (10.7.4). All apps always start frontmost, in Terminal and in Applescript Editor. Sure, i pasted your suggestion too.
I was tired to use:

	launch application a
	do shell script "sleep 0.5"
	tell application "System Events" to if exists process a then set visible of process a to false

.but i have to, if other options doesn’t work.

open -ga <application name>

That opens an application and make it foreground after the current front most application. So what really happens is, it makes it frontmost and then switches to back to the front most application. That said means that for instance the Finder is level 9 (z-index) and and when you use ‘open -ga Finder’ in terminal the terminal remains level 0 but the Finders becomes level 1. When you use this in a script and run it (by itself), the script will quit when finished and the Finder will become top level (level 0) application. So it looks like it becomes front most.

Examples:
When the following code is saved in a script and run by double clicking in the Finder (run by itself) you’ll notice that the Finder becomes frontmost:

do shell script "open -ga Finder"

When that same code is above is executed by Script Editor, you’ll notice the script stays up front.

Hi Bazzie,
i got it but actually ga ( :slight_smile: ) make no sense to me, isnt there another command i could use to start apps not frontmost ?

Hello Joy.

The handler below should work as long as the bundle name of the application and the application name is the same.

You can rework it to an osascript should you want to run it from the commandline.

startUnseen for "Finder"

on startUnseen for thisApp
	if running of application thisApp is false then tell application thisApp to activate
	tell application id "sevs" to set visible of application process thisApp to false
end startUnseen

Edit
This won’t work with applications that aren’t well behaved. Like VLC.App, which works perfectly with open -ga.