• 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: Testing for last process used
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Testing for last process used


  • Subject: Re: Testing for last process used
  • From: kai <email@hidden>
  • Date: Wed, 11 Jan 2006 15:55:18 +0000


On 10 Jan 2006, at 04:02, Brett Conlon wrote:

Is there a way to test for the last process used?

I see that you're already considering UI scripting for this, Coj - but I'll throw the following into the pot anyway, FWIW:


-------------------

to getLastProcess()
tell application "System Events"
tell (get first process whose frontmost is true)
set visible to false
repeat while visible
delay 0.1
end repeat
end tell
set lastProcess to name of (get first process whose frontmost is true)
if lastProcess is "Finder" and (count (processes whose visible is true)) > 1 then
tell process "Finder"
set visible to false
repeat while visible
delay 0.1
end repeat
end tell
set lastProcess to name of (get first process whose frontmost is true)
ignoring application responses
set process "Finder"'s visible to true
end ignoring
end if
end tell
lastProcess
end getLastProcess


set lastProcess to getLastProcess()
tell application lastProcess to display dialog "Process \"" & lastProcess & "\"" (* demo *)


-------------------

That obviously assumes your script doesn't want to target Finder. If it does, then the handler could be abbreviated to:

-------------------

to getLastProcess()
	tell application "System Events"
		tell (get first process whose frontmost is true)
			set visible to false
			repeat while visible
				delay 0.1
			end repeat
		end tell
		name of (get first process whose frontmost is true)
	end tell
end getLastProcess

set lastProcess to getLastProcess()
tell application lastProcess to display dialog "Process \"" & lastProcess & "\"" (* demo *)


-------------------

---
kai


_______________________________________________ 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
References: 
 >Testing for last process used (From: Brett Conlon <email@hidden>)

  • Prev by Date: Various Qs about Intel and AppleScript
  • Next by Date: Re: Various Qs about Intel and AppleScript
  • Previous by thread: Re: Testing for last process used
  • Next by thread: Substituting a variable in UI scripting
  • Index(es):
    • Date
    • Thread