Re: Using tell application "name" where the name comes from GUI Script...
Re: Using tell application "name" where the name comes from GUI Script...
- Subject: Re: Using tell application "name" where the name comes from GUI Script...
- From: Bill Cheeseman <email@hidden>
- Date: Wed, 16 Apr 2003 12:44:51 -0400
You don't have to tell the application to quit, because you already have a
reference to the application process. You can just tell the process to quit.
You don't have to bring it to the front, either. And because you obtained
the process reference without using its name, you are able to avoid the fact
that you normally can't tell an application to do something by putting the
application's name in a variable.
In general, a tell block addressed to an application must include the
application's name as an actual string. A variable that has been set to a
string value won't work. For a general discussion of this issue, see
<
http://www.applescriptsourcebook.com/tips/launchbycreator.html> and
<
http://www.applescriptsourcebook.com/tips/tellbyvariable.html>.
I don't want to tell all my applications to quit, so the following example
just displays the name of each -- click OK or hit RETURN to cycle through
all the application processes. It illustrates the basic idea behind using
the process reference. Just substitute 'quit' for 'display dialog name as
string' -- but, as noted, I haven't tested this with 'quit'.
tell application "System Events"
repeat with aProcess in every application process
tell aProcess
if accepts high level events and ,
not (creator type = "lgnw") and ,
not (creator type = "syui") and ,
not (creator type = "MACS") and ,
not (creator type = "sevs") then
display dialog name as string
end if
end tell
end repeat
end tell
I used 'application process' instead of 'process' because you normally would
only want to try to quit application processes.
I'm not sure this will do what you hope, however. Pay close attention to the
names of the processes displayed by my version of the script. It includes
the Dock and lots of other processes that you might want to keep around.
on 03-04-16 10:56 AM, Kevin Bohan at email@hidden wrote:
>
I have about a day's experience Apple Scripting and I have bee trying to use
>
the new Apple Script GUI to control the process currently running on my
>
system. I figured if I iterate through the process I could "tell" each
>
application to do something. In the example below I have each application
>
quitting, except it doesn't work. It appears to me this is because of the
>
weak typing in Apple Script, what appear to be just a string when you type
>
>
tell application "Finder" to something
>
>
is not interpreted the same as me having
>
>
tell application curr_name to something
>
>
as below, even if the value of curr_name is "Finder". Can someone explain to
>
me how this should work, and how to fix it?
>
>
Thanks,
>
>
Kirby
>
>
Here's the code:
>
>
>
tell application "System Events"
>
set process_list to get every process
>
repeat with counter from 1 to count of process_list
>
>
set curr_proc to item counter of process_list
>
if accepts high level events of curr_proc = true and ,
>
not (creator type of curr_proc = "lgnw") and ,
>
not (creator type of curr_proc = "syui") and ,
>
not (creator type of curr_proc = "MACS") and ,
>
not (creator type of curr_proc = "sevs") then
>
set frontmost of curr_proc to true
>
set curr_name to name of curr_proc
>
tell application curr_name to quit
>
end if
>
end repeat
>
end tell
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.