How do I start an app but keep it hidden?

I am making a small script for the freeware anti-virus program ClamXav. It has a “Sentry” menulet that watches incoming files for (Windows) viruses so you don’t pass them on. The Sentry is turned on from within the main ClamXav application or on startup, but I want to be able to start just the Sentry without going through the layers of the app.

So, I wrote a script and it almost works the way I want it to:

activate application "ClamXav"
--turn on ClamXav
 tell application "System Events"
	get system attribute "sysv"
	 if result is greater than or equal to 4144 then -- Mac OS X 10.3.0
		--checks to see if Access for Assitive Devices is turned on in System Preferences.  Makes it so the script can click on menus and stuff. Access helps us even if we"re not disabled.
		if UI elements enabled then
			tell application process "ClamXav"
				delay 1
				 --we wait a second for ClamXav to finish opening, then start the Sentry.
			end tell
				click menu item "Launch ClamXav Sentry" of menu 1 of menu bar item "File" of menu bar 1
		else
			beep
			    --this is what happens if you don't have Access turned on.
			display dialog "GUI Scripting is not enabled" & return & return & "Open System Preferences and check Enable Access for Assistive Devices in the Universal Access preference pane, then run this script again." with icon stop
			if button returned of result is "OK" then
				tell application "System Preferences"
					activate
					set current pane to pane "com.apple.preference.universalaccess"
				end tell
			end if
		end if
	else
		beep
		display dialog "This computer cannot run this script" & return & return & "The script uses GUI Scripting technology, which requires an upgrade to Mac OS X 10.3 Panther or newer." with icon caution buttons {"Quit"} default button "Quit"
	end if
	--and then we close ClamXav
	quit application "ClamXav"
 end tell

When I do this, ClamXav opens it’s main window, opens the Sentry and then quits, cool. Now is there a way to open it’s window in the background or hidden, so I never see it? That would be cleaner I think.

I have tried the “set the visible to false” option, but the app’s window appeared first, then dissapeared. Can I make it never appear but still do it’s simple command to launch the Sentry?

Thanks much from a beginner, Bruce in Vancouver, BC

Try this tip: http://bbs.applescript.net/viewtopic.php?id=14916

There are a few other threads on similar topics, if this does not work the way you want. Just log onto the bbs, and use the Search function (available along the top menu) and try different combinations of keywords.

Another way, to avoid flicker, might be to forget UI scripting and use “System Events”:


tell application "TextEdit" to launch
tell application "System Events" to set visible of application process "TextEdit" to false

I just solved my whole problem easily. If I hadn’t missed this before I wouldn’t have had the fun of making the above (now unnecessary) script.

I wanted to start the virus monitoring “sentry” program and couldn’t find it with Spotlight. It just occured to me that if it started at Login, then it might be in my Login Items in system preferences. It was, but where was it located? I hovered over the Login Item for ClamXavSentry, and the tag said It was one of the hidden files inside the main app folder.
/Applications/Utilities/ClamXav.app/Contents/Resources/ClamXavSentry.app
Aha. Well, now I just ctrl click on ClamXav and go to “show package contents” to open it up, and make an alias of of the Sentry program I find hiding in there. Now I can start it whenever I want.
So, there I go, thanks for all your help!

By the way, I never did find how to not make the main app flick on, since I was using it to activate the Sentry. Oh well.

There is a free program out there called “Drop Script Backgrounder”. It will convert your script/program into a hidden program, and it is easy to use. i used it, and it is awsome.