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