Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Apple Script help

Apple Script help
Thread Tools
Grizzled Veteran
Join Date: May 2000
Location: Any Town, USA
Status: Offline
Reply With Quote
Jan 31, 2001, 07:56 AM
 
In my app (being made with REALbasic) . . . I have a global floating window (among other thing) . . . and I have two buttons on it. One to hide the current open app, and another to quit the current open app.

I origionally tried to do this with Apple Events, but that was a little messy. I thought that AS would be a little easier.

I know what I want to do . . but just dont really have the syntax to make these Apple Scripts. I want something like:

"tell open application (or current application) to quit"
and
"tell open application (or current application) to hide"

Anyone know how I can do this?
Thanks
Change your world and you will change your mind.
     
Dedicated MacNNer
Join Date: Nov 1999
Location: Georgetown, Demerara, Guyana
Status: Offline
Reply With Quote
Feb 5, 2001, 12:19 PM
 
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
     
Grizzled Veteran
Join Date: May 2000
Location: Any Town, USA
Status: Offline
Reply With Quote
Feb 5, 2001, 12:46 PM
 
Thanks so much Paul. I thought of that. I have a global floating window (my app), and the buttons on it will hide the CURRENT app/quit the CURRENT app.

Now I got to fildde around with the great help you have given me. Thanks again.
Change your world and you will change your mind.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:08 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2