• 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: How to determine whether launched automatically at login
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to determine whether launched automatically at login


  • Subject: Re: How to determine whether launched automatically at login
  • From: Jeff Porten <email@hidden>
  • Date: Mon, 15 Aug 2005 23:14:16 -0400

On Aug 3, 2005, at 1:56 PM, Laine Lee wrote:

How can I configure my Applescript application to determine at run time
whether it was launched automatically as a login item or whether it was
launched arbitrarily by the user? Thanks.

This might be good enough for government work....

Upon login, one of the first processes to start is loginwindow. You can get the launch time of loginwindow by parsing the results of

do shell script "ps -uxww | grep loginwindow"

A login startup item will almost certainly show a launch time within a minute or two of loginwindow's. Arbitrarily launched applications will be later... usually. The caveat is because I note that I launched Script Editor and Safari within two minutes after loginwindow, and those were both manual. But maybe I'm quicker on the trigger than your users.... At the very least, this gives you a heuristic for a good guess.

A perfect algorithm just occurred to me, but it's would take some serious geek fu to implement. In pseudocode, the following would be part of your application:

set loginFile to plistWhichContainsUserStartupItems
set userItemCount to my parseToCountStartupItems(loginFile)
set userItemCount to userItemCount + 5 -- loginwindow, Dock, SystemUIServer, Finder, System Events; YMMV if you're not using Tiger


set currAppCount to do shell script "ps -ux | grep '.app' | wc -l" -- counts currently running apps

if currAppCount ≤ userItemCount then
-- fewer apps running total than will launch at startup, hence this is a startup item
else
-- I was run manually sometime later
end if


Best,
Jeff _______________________________________________
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


  • Follow-Ups:
    • Re: How to determine whether launched automatically at login
      • From: kai <email@hidden>
References: 
 >How to determine whether launched automatically at login (From: Laine Lee <email@hidden>)

  • Prev by Date: Re: Best way to tell if a file copy has finished.
  • Next by Date: Re: Scripting TextEdit Save As HTML?
  • Previous by thread: How to determine whether launched automatically at login
  • Next by thread: Re: How to determine whether launched automatically at login
  • Index(es):
    • Date
    • Thread