VMware Communities
xltrader
Contributor
Contributor
Jump to solution

How can I tell in Applescript whether XP or OSX has the top window?

I have some Applescripts that I want to launch when I click on either a file or some selected text in either OSX or in XP, with different scripts for file or text, and another different set of scripts for OSX or XP. I've got everything working except for how to tell AS what I clicked on, especially in Unity Mode, but really in any Mode. I tried the Applescript forums but got no nibbles so I'll try you folks. Surely this is something that comes up all the time when working with Fusion and two OS's running side by side.

0 Kudos
1 Solution

Accepted Solutions
thf
Enthusiast
Enthusiast
Jump to solution

Hi Again...

My apologies if you already know all this, but you might use the applescript script editor's "open dictionary..." to look through the capabilities of "System events. app" (in system/library/coreservices/"). Looks like "standard suite / aplication / frontmost' and "processes suite / processes / frontmost" might relate to what you're trying to do.

Those who've said "this isn't really a Fusion issue" are correct - you don't really want info from Fusion, you want it from the system and/or finder. As far as the system is concerned, whether a window belongs to fusion or to photoshop is pretty much irrelevant. That's why you'll have better luck pursuing this on an applescript forum than here.

Good luck,

Tom

View solution in original post

0 Kudos
7 Replies
WoodyZ
Immortal
Immortal
Jump to solution

Fusion does not support AppleScript and although you may have already tried nonetheless an AppleSript centric forum would be a better place to be looking for an answer as AppleScipt is running under OS X not Fusion.

0 Kudos
xltrader
Contributor
Contributor
Jump to solution

Thanks, Woody, but it's really not an Applescript question. I should have narrowed it down to the real issue and not even mentioned Applescript.

I have two windows visible, a Mac window and an XP window. I click on something in one of them, and I want to be able to tell (programmatically) if the current front window (after my click) is Mac OS or Windows OS. That's the root of my question. Which OS is now the front OS after my click? What test can I make or what signpost can I look for (again, programmatically) that will give me that info?

0 Kudos
WoodyZ
Immortal
Immortal
Jump to solution

AppleScript or not if your writing a program in whatever language it still isn't a Fusion issue per-se and in any case there certainly has not been enough details presented to matter other then to say look at the language your programing in and what API's it can access and program accordingly.

In other words the fact that one of the window belongs to Fusion or any other program shouldn't make a difference from a programmatic standpoint.

Although without knowing more of the particulars thats easier said then done.

0 Kudos
thf
Enthusiast
Enthusiast
Jump to solution

Hi...

It's been a while since I was applescripting, but can't you get the window list from the finder, then walk down the list checking titles (and maybe attributes more of interest to you) ??

I should think one could quickly put together a little test script that would put the window list into an alert dialog , just for test purposes.

Sorry not to be more specific.

Additionally, I just now got, via google, this snippet from macosxhints.com:

-


tell application "System Events"

set myFrontMost to name of first item of (processes whose frontmost is true)

end tell

-


I don't know what all info you might get from "processes whose frontmost is true", but it sounds like it might relate to what you're looking for.

Tom

0 Kudos
thf
Enthusiast
Enthusiast
Jump to solution

Hi Again...

My apologies if you already know all this, but you might use the applescript script editor's "open dictionary..." to look through the capabilities of "System events. app" (in system/library/coreservices/"). Looks like "standard suite / aplication / frontmost' and "processes suite / processes / frontmost" might relate to what you're trying to do.

Those who've said "this isn't really a Fusion issue" are correct - you don't really want info from Fusion, you want it from the system and/or finder. As far as the system is concerned, whether a window belongs to fusion or to photoshop is pretty much irrelevant. That's why you'll have better luck pursuing this on an applescript forum than here.

Good luck,

Tom

0 Kudos
xltrader
Contributor
Contributor
Jump to solution

Boy, I'm glad I asked. That System Events Dictionary contained a wealth of stuff I didn't know about, including the answer to my question. Thanks very much for the reference.

I still respectfully disagree about this being the right place to ask that question, over and above the fact that it produced the Right Answer, which is a pretty good argument by itself. But that question could not ever arise if I was working only in Windows, or only in OSX. The only time that question has any relevance is when I'm working on both at once under Fusion or one of it's lesser kin. So where better to ask a question about working on two OS's side by side? Who has more experience doing that than this group?

Anyway, thanks again and Happy New Year to you.

0 Kudos
WoodyZ
Immortal
Immortal
Jump to solution

That System Events Dictionary contained a wealth of stuff I didn't know about, including the answer to my question. Thanks very much for the reference.

Being that System Events is typically one of the more/most often calls being made when using AppleScript looking into its Dictionary or any Dictionary for that matter is SOP when programing with AppleScript and information like this is readily available in AppleScript centric forums/web sites so I would find that this is only a revelation to someone that hasn't done much programmer to begin with. The File > Open Dictionary... command in AppleScript is there for a very good reason and it's not rocket science.

I still respectfully disagree about this being the right place to ask that question, over and above the fact that it produced the Right Answer, which is a pretty good argument by itself.

First of all not only is AppleScript not supported by Fusion any coding in AppleScript to ascertain who the topmost window belongs to has nothing to do with Fusion from a programmatic standpoint as the target one is look for is going to be user defined and the same code is going to be interchangeable by substituting whatever the target might be for the target at that point in the code even if it happed to be a window belonging to Fusion or any other Applications window for that matter.

Secondly I never said that this wasn't the right place to to ask and the main thrust of my first reply was two fold to let you know that AppleScript isn't supported in Fusion and that AppleScript centric forums/web sites are typically a better places to be looking for help with AppleScript. That certainly doesn't mean that you will not find something useful here nor does it mean you can't ask either.

With no offense indented to Tom and keeping in mind that you explicitly said "but it's really not an Applescript question" even though you asked "How can I tell in Applescript..." then that negates Toms answer as being correct much less the fact that this same information is already out in the Internet and with a little searching it could/would have been found other then having it being repeated again here. I know because I've seen that same information out on the Internet before by searching for the answer to a question similar to yours.

Don't get me wrong I'm glad that if what was presented in the forum helps you solve your problem however as a programmer myself I can assure you that every bit of code I've use as an example of what I wanted to program I've found much quicker in forums centric to the language I'm programing in, and that goes for all the AppleScripts scripts I've written that are used with Fusion as well, then in a forum such as in this case and is why suggesting you search it's a very valid reply in a case such as this.

But that question could not ever arise if I was working only in Windows, or only in OSX. The only time that question has any relevance is when I'm working on both at once under Fusion or one of it's lesser kin. So where better to ask a question about working on two OS's side by side? Who has more experience doing that than this group?

Again enumerating windows and who owns them and acting according is SOP and how that is done programmatically the structure of a function to do that should work regardless of the fact that the windows belongs to Fusion or any other application. In other words writing reusable code and passing functions variables is a typically considered a better and more professional approach then hard coding something that may only be good for one thing and in that respect AppleScript doesn't care whether the topmost window is a window belonging to Fusion or iTunes for that matter. So as far as I'm concerned your question was more relevant to AppleScript and programming in general then it is specifically to Fusion.

0 Kudos