Call an application process
Call an application process
- Subject: Call an application process
- From: KOENIG Yvan <email@hidden>
- Date: Sat, 8 Mar 2008 14:36:28 +0100
Hello
From time to time, I’ running simultaneously two copies of Numbers.
One is running in French, the other striiped of localsed resources
run in English. The second one is names « NumbersAnglais.app ».
When I want to drive one of them I must use GUI scripting.
Alas, the two copies return the same process’s name.
The properties of the french one are :
get properties of process 18
{class:application process, entire contents:{}, focused:missing
value, displayed name:"Numbers.app", orientation:missing value,
partition space used:0, maximum value:missing value, file:alias
"Macintosh HD:Applications:iWork '08:Numbers.app:", position:missing
value, subrole:missing value, selected:missing value, help:missing
value, size:missing value, visible:true, role:"AXApplication",
application file:alias "Macintosh HD:Applications:iWork
'08:Numbers.app:", background only:false, accepts high level
events:true, Classic:false, file type:"APPL",
description:"application", has scripting terminology:false,
name:"Numbers", accepts remote events:false, unix id:289, creator
type:"NMBR", id:3014657, value:missing value, enabled:missing value,
title:"Numbers", minimum value:missing value, total partition size:0,
frontmost:true}
The properties of the English one are :
get properties of process 20
{class:application process, entire contents:{}, focused:missing
value, displayed name:"NumbersAnglais.app", orientation:missing
value, partition space used:0, maximum value:missing value,
file:alias "Macintosh HD:Applications:iWork '08:NumbersAnglais.app:",
position:missing value, subrole:missing value, selected:missing
value, help:missing value, size:missing value, visible:true,
role:"AXApplication", application file:alias "Macintosh
HD:Applications:iWork '08:NumbersAnglais.app:", background
only:false, accepts high level events:true, Classic:false, file
type:"APPL", description:"application", has scripting
terminology:false, name:"Numbers", accepts remote events:false, unix
id:303, creator type:"NMBR", id:3670017, value:missing value,
enabled:missing value, title:"Numbers", minimum value:missing value,
total partition size:0, frontmost:true}
Which identifier may I use to be sure that I will speak to the
correct one ?
tell application process "Numbers" is wrong because it will call the
French one when I want the English one.
I tried to use
tell (application process whose id is 3670017) but it fails.
tell (application process whose unix id is 303) fails too
So at this time, I found nothing better than :
--script1
property theApp : « NumbersAnglais »
tell application theApp to activate
tell application « System Events »
tell application process (my whichProcess())
--
end tell
end tell
-- =============
(*
An application named "NumbersAnglais.app" may be already running,
the script has activated "Numbers.app"
but the two apps named their process "Numbers".
We must check the "displayed name" to identity the correct one
*)
on whichProcess()
local lp, r, i
tell application "System Events" to set lp to (displayed name of
processes)
repeat with i from 1 to count of lp
set r to 0
if item i of lp is (theApp & ".app") then
set r to i
exit repeat
end if
end repeat
return r (* the index of the process in the list *)
end whichProcess
--=============
--end1
or
--script2
property theApp : « NumbersAnglais »
tell application theApp to activate
tell application « System Events »
set listeP to (displayed name of processes)
tell application process (my whichProcess(listeP))
--
end tell
end tell
with
-- =============
(*
An application named "NumbersAnglais.app" may be already running,
the script has activated "Numbers.app"
but the two apps named their process "Numbers".
We must check the "displayed name" to identity the correct one
*)
on whichProcess(lp)
local r, i
repeat with i from 1 to count of lp
set r to 0
if item i of r is (theApp & ".app") then
set r to i
exit repeat
end if
end repeat
return r (* the index of the process in the list *)
end whichProcess
-- =============
--end2
The first one is easier to use but I’m wondering which is the one
which make me sure that the index of the process will not change
between the creation of the list and the call to the process.
Yvan KOENIG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden