OS X – AppleScript to open Apps Hidden

I need to open Safari with a specific URL on command line. The problem is that this has to happen completly in background and should be started through an existing bashscript.
Here is my solutiuon, it should apply to any other app in OS X SnowLeopard. You need to call the bash schript like this:


./open_safari_with_url.sh "http://www.site_i_want_to_visit.com"

“open_safari_with_url.sh” looks like this:


#!/bin/bash
osascript -e "
tell application \"Safari\" 
	tell application \"Finder\"
		set visible of process \"Safari\" to false
	end tell
	launch
	set the URL of document 1 to \"$1\"
end tell"

[EDIT] It seems that ‘launch’ in AppleScripts starts the app in background. So we don’t need to tell Finder to hide Safari anymore.

tell application "Safari" 
	launch
	set the URL of document 1 to "http://whatever..."
end tell"

open terminal here

Marc Liyanage wrote a nice Apple Script which easily allows you to switch from the Finder to the Terminal.
Just download it here and drag the script to the upper free space in the Finder.

Clicking it results in a new Terminal window which location is the same as the Finder location.
new Finder icon

Here’s how it looks.

P.S. this works under OS X 10.6 😉