I am back again with a problem arising from use of “LSUIElement”.
Before making the App’s menu bar disappear using “LSUIElement”, I had scripted to make sure that whenever the user switched to iTunes, the App window would come to the front. Conversely, if the user switched to the App, iTunes would be activated immediately behind the App. This way, the user woud always have the App in his face when switching to iTunes until the App had finished its task - showing progress of the vanilla script. The code I put in to do this is in a handler that gets called regularly:
on checkWindowstate(last_Looked_iTunes)
if ((frontmost of application "iTunes") is true) or (frontmost of application "My App" is true) then
if last_Looked_iTunes ≠true then
tell application "iTunes" to set visible of window "iTunes" to true
set last_Looked_iTunes to true
end if
else
set last_Looked_iTunes to false
end if
tell application "System Events"
if (visible of process "iTunes") is false then
set visible of process "My App" to false
end if
end tell
return last_Looked_iTunes
end checkWindowstate
Since making the App’s menu bar disappear by building it with “LSUIElement” in the info.plist, I am unable to replicate the behaviour I had before. After all my unsuccessful attempts to replicate the old behaviour, I have now turned off all window manipulation in the script (ie it no longer calls to checkWindowstate). What now happens is this:
(1) I run the vanilla script from the iTunes menu which fires up the App. All is fine at this stage. The App sits in front of iTunes showing progress.
(2) I to the Finder (for example). The iTunes windows and the App are obscured by Finder windows.
(3) I back to iTunes. The iTunes menu bar appears but the iTunes window fails to come to the front. There is no sign now of the App window.
(4) If I to Safari then back to iTunes, the menu bar stays stuck on iTunes (but greyed out).
(5) By ing backwards, I can sometimes get the iTunes window to appear but not the iTunes menu bar
(6) Running a short test applescript from Script Editor along these lines will make the App come to the front:
tell application "My App"
activate
show window 1
end tell
(7) However, doing the same test script for iTunes (or any test script hoping to make iTunes react and come to the front), leaves the test script hung. Only quitting out of “My App” will allow me to exit the test script.
(8) I can always recover by using exposé to locate My App’s window and cancel out using the cancel button in My App.
I am not clear on what is going on and why I am unable to control the relative position/visibility of “My App” and “iTunes”. Basically, as it currently stands, if the user tabs out of iTunes while the vanilla script is running, he can only recover by using exposé to find the progress window in My App.
Can anyone shed light on this behaviour and advise how I may recover control of my windows?