point to the next app in the stack

Hi all,

Is any idea how to point to the next app in the stack if myApp is frontmost? (ie if index of frontmost=0, point to app with index 1)


tell application "System Events"
	set FMn to (name of application processes where it is frontmost)
	set currApp to item 1 of FMn
	if currApp = "myApp" then
		set currApp to= ...?
	end if
end tell

Hi,

try this


set myApp to "iTunes"

tell application "System Events"
	set FMn to name of 1st application process whose background only is false and frontmost is true
	set allPrc to (name of application processes whose background only is false)
	if FMn is myApp then
		repeat with i from 1 to (count allPrc)
			if item i of allPrc is myApp then
				if i = (count allPrc) then
					set frontmost of process (item 1 of allPrc) to true
				else
					set frontmost of process (item (i + 1) of allPrc) to true
				end if
				exit repeat
			end if
		end repeat
	end if
end tell

Thanx Stefan, but what’s about list of allowed apps?

set myApp to {"Adobe Photoshop CS3", "Adobe Illustartor", "Adobe InDesign CS3", "Distiller", "Finder", "AdobeAcrobat", "Mail", "TextEdit"}

Script should determine which app in appList is frontmost at the moment – if none, wait until it becomes

Do you mean something like this?


property myApps : {"Adobe Photoshop CS3", "Adobe Illustrator", "Adobe InDesign CS3", "Distiller", "Finder", "AdobeAcrobat", "Mail", "TextEdit"}

tell application "System Events"
	repeat until name of (1st application process whose background only is false and frontmost is true) is in myApps
		delay 1
	end repeat
end tell

You are really guru!

One more question if possible:
it seems like active process can’t get access to writing to log file:
I’ve tried switch to Finder but result the same :frowning:
Howevwer outside the scope of process currApp the log file is opened

on idle
set myFile to (POSIX file "/log.txt") as alias
property myApps : {"Adobe Photoshop CS3", "Adobe Illustrator", "Adobe InDesign CS3", "Distiller", "Finder", "AdobeAcrobat", "Mail", "TextEdit"}

tell application "System Events"
   repeat until name of (1st application process whose background only is false and frontmost is true) is in myApps
end repeat
set currApp   to name of (1st application process whose background only is false and frontmost is true)
tell process currApp
					try
						set currDoc to name of first window
						set currTime to current date
						tell Finder-- ??
							set ff to open for access myFile with write permission
							set l to currApp & ">>" & currDoc & " >> " & currTime & return
							write l to ff starting at eof
							close access ff
						end tell
					end try
				end tell
return 10
end on idle

read /write is part of Standard Additions, there is no target application or process required