Hi crazyjohnson,
There are a number of methods available in AppleScript to hide and/or quit an application (process), including the frontmost one. However, note that AppleScript's built-in 'current application' spec normally refers to the currently running "script host" (e.g., an applet or a script editor), not necessarily the frontmost application. On the other hand, a command to obtain the frontmost process might not return the process you expect, if the check is being made from within an applet (or script) that's running in the foreground rather than the background; in this case, the applet (or script host) itself would be the frontmost process. [In other words, these are much the same caveats as those that apply when directly using Apple Events.]
Assuming that your script or applet is launched into the
background (e.g., via the "double applet" technique, or via a dedicated background script-launcher/-scheduler), and that the Finder is readily available (e.g., you won't ever be running under Panels in a Multiple Users setup), then it is possible to accomplish your tasks by using the Finder's process-related commands. For some examples of using these commands, please see the earlier related threads in this Forum (e.g., the
simple applescript question thread and the
Hiding thread). For instance, you could quit or hide the frontmost process by doing something like the following:-
Code:
[...]
-- [Side Note: Under Mac OS 8.1-, you might not need to say 'item 1 of ...']
-- To QUIT the frontmost app
tell application "Finder"
set theFrontmostAppAsList to (every application process where its frontmost is true)
set theFrontmostApp to (item 1 of theFrontmostAppAsList)
set theFrontmostAppName to (name of theFrontmostApp)
end
tell application theFrontmostAppName to quit
-- To HIDE the frontmost app
tell application "Finder"
set theFrontmostAppAsList to (every application process where its frontmost is true)
set theFrontmostApp to (item 1 of theFrontmostAppAsList)
set (visible of theFrontmostApp) to false
end
[...]
Otherwise, if the Finder will not be readily available, you could use the various process-related commands offered by appropriate third-party scripting additions (OSAXen), such as the 'Akua Sweets' OSAX; many suitable OSAXen are listed in MacScripter.net's
Scripting Additions Library.
[BTW, for an example of how to use the "double applet" technique (where one applet asynchronously launches another applet into the background, without the need for a dedicated background script-launcher/-scheduler), please see my post of '12-12-1999 12:35 PM' in the
Speaker volume script thread (and, for additional info from Apple, see also the one of '06-06-2000 01:40 AM' in the
remote access connect thread) in this Forum.]
Regards,
--Paul