• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: path to frontmost application: bug in AS 1.9.3?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: path to frontmost application: bug in AS 1.9.3?


  • Subject: Re: path to frontmost application: bug in AS 1.9.3?
  • From: Donald Hall <email@hidden>
  • Date: Sat, 2 Oct 2004 00:01:07 -0600

Title: Re: path to frontmost application: bug in AS 1.9.3?
Paul,

Thanks for your comments. (Also thanks to Jakob Peterhänsel.)

As soon as I sent the message, I realized I should have been using "Systems Events", not "Finder". Still using it out of old habits, I guess. Your speculation about the revised status of the Screen Saver Engine makes sense to me. Unfortunately, it breaks my script.

I am concerned about how long this check takes, because there are times when my idle handler return time is set to 1 second and the handler does a lot more than just look for the screen saver. I used the following test script to see if there is any extra time needed using "System Events" to get the name of the frontmost process:

set startTime to (current date)
repeat with i from 1 to 100
        -- Test A:
      --set frontProc to name of (info for (path to current application))
        -- Test B:
      --tell application "System Events" to set frontProc to (name of every process whose frontmost is true)
        -- Test C:
        tell application "Finder" to set frontProc to (name of every process whose frontmost is true)
        if "ScreenSaverEngine" = frontProc then set r to true
end repeat
set elapsedTime to (current date) - startTime

Results for elapsedTime are:

Test A: 17 seconds
Test B: 8 seconds
Test C: 10 seconds (a little longer as expected; hands off to System Events)

So it appears telling System Events to do the job is the quickest in any case!

Out of curiosity, I ran a fourth test:

set startTime to (current date)
repeat with i from 1 to 100
        tell application "System Events" to set allProcs to name of every process as text
        if "ScreenSaverEngine" is in allProcs then set r to true
end repeat
set elapsedTime to (current date) - startTime

This test produced an elapsed time of only 5 seconds with 20 processes running. This is probably the safest test to make for the presence of the screen saver, just in case the frontmost of the screen saver is also not set to true at some time in the future.

Regards,

Don


On 9/30/04 11:11 PM, "Donald Hall" <email@hidden> wrote:
> I have a script with an idle handler containing the following statement:
>
>         set frontProc to name of (info for (path to frontmost application))
>
> In AS 1.9.3, OS 10.3.5, when the screen saver is running this statement does
> not give the expected result of "ScreenSaverEngine", but rather the name of
> the application that was frontmost just prior to the screen saver starting. In
> Jaguar the statement gave the expected result.
>
> In Panther if instead of the above statement I use:
>
> tell application "Finder" to set frontProc to name of every process whose
> frontmost is true
>
> frontProc is set to "ScreenSaverEngine" as expected.
>
> Is this a bug or a feature?
>
> Is there a time penalty for using the Finder, or is there another way to get
> the name of the frontmost application?

I suspect that this is related to the documented change (Release Notes) of
AppleScript 1.9.2 (OS 10.3):

"
 Scripts that use the path to frontmost application command will now get the
correct path when run from the Script Menu menu extra. Previously, the
command would return the path to System Events. [3084984]

"
By referring to the new implementation as "the correct path" the implication
is that the former result  which returned the name of the faceless
background application running the script (System Events) should never be
considered frontmost even though it was running the script. That makes sense
to me. Probably the Screen Saver is also not to be considered frontmost in
the sense of a regular application. Or else this was an unintentional result
of the change and should be corrected.

As I recall, 'path to current application' will still get you System Events
in that context. See what happens if you try 'current application'.

I'm not quite sure why you refer to a "time penalty" for the Finder. Surely
it doesn't change if you do nothing for 3 minutes (leaving Screen Saver in
place)? It's a difference between the 'frontmost application ' determined by
the standard addition and frontmost process determined by the Finder. (You
probably should be using System Events, not the Finder, to get the frontmost
process in any case.) Maybe there's meant to be a difference, or maybe one
of them is wrong.

--
Paul Berkowitz


--
Donald S. Hall, Ph.D.
Apps & More Software Design, Inc.
email@hidden
http://www.appsandmore.com
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Variable Ponderance
  • Next by Date: It can be done, but does it make any sense?
  • Previous by thread: Re: path to frontmost application: bug in AS 1.9.3?
  • Next by thread: Volume status
  • Index(es):
    • Date
    • Thread