What is "system events" ?


Jean-Christophe Helary <jean.christophe.helary@...>
 

Is there a place that describes what System Events is, how it works, why it is necessary for some sorts of scripting, etc.?

Jean-Christophe


Bill Cheeseman
 

There are links and a lot of commentary on my website: http://pfiddlesoft.com. Look at the UI Browser section first, then maybe the frameworks page.

On Oct 20, 2017, at 4:40 AM, Jean-Christophe Helary <jean.christophe.helary@...> wrote:

Is there a place that describes what System Events is, how it works, why it is necessary for some sorts of scripting, etc.?

-- 

Bill Cheeseman - wjcheeseman@...


Jean-Christophe Helary <jean.christophe.helary@...>
 

Thank you Bill.

Jean-Christophe 

On Oct 20, 2017, at 18:09, Bill Cheeseman <wjcheeseman@...> wrote:

There are links and a lot of commentary on my website: http://pfiddlesoft.com. Look at the UI Browser section first, then maybe the frameworks page.

On Oct 20, 2017, at 4:40 AM, Jean-Christophe Helary <jean.christophe.helary@...> wrote:

Is there a place that describes what System Events is, how it works, why it is necessary for some sorts of scripting, etc.?


2551phil
 

Cross-posting isn’t an issue here since these are all AppleScript groups, and may not have the same members.

As to the question, System Events is an app, like any other app (sort of). It lives here:

/System/Library/CoreServices/System Events.app

The thing that makes it different is that it doesn’t have a GUI, and it’s whole purpose is to be accessed through Applescript for scripting (as it’s name implies) system functions such as inspecting running processes, sleeping, restarting and shutting down the computer. It can do quite a few other things, too, which you can explore through its Dictionary.


Best


Phil
@sqwarq


2551phil
 


On 20 Oct 2017, at 22:50, 2551phil <2551phil@...> wrote:

 it’s whole purpose is to be accessed through Applescript

Before I get spanked for that, I should say “through any OSA-compliant language" (but the only one worth knowing is, of course, AS).

It’s oft-mentioned around here, but haven’t seen it mentioned for a while, but if you’re looking to really understand the innards of AppleScript, you need to start (and for most questions you’ll end) here:


Don’t be put of by the date. Most of what it contains is still relevant, and more importantly is the only source you’ll find for quite a lot of essential info.

I’ve read it at least 3 times, and I probably need to re-read it again. Too much juicy stuff to be taken in with only a couple of readings.



Best


Phil
@sqwarq





Jean-Christophe Helary <jean.christophe.helary@...>
 

Thank you Phil.

On Oct 21, 2017, at 0:50, 2551phil <2551phil@...> wrote:

As to the question, System Events is an app, like any other app (sort of). It lives here:

/System/Library/CoreServices/System Events.app

The thing that makes it different is that it doesn’t have a GUI, and it’s whole purpose is to be accessed through Applescript for scripting (as it’s name implies) system functions such as inspecting running processes, sleeping, restarting and shutting down the computer. It can do quite a few other things, too, which you can explore through its Dictionary.

In one of the references that Bill mentioned (Matt Neuburg's TidBits article), there is a very enlightening explanation:


Blessed (System) Events -- At some point, someone at Apple put two and two together, as follows. "On the one hand, we've got the Accessibility API, which lets any program access the interface elements of any other program. On the other hand, we've got AppleScript, which lets any user write a script to give commands to any scriptable program. So what would happen if we put them together? Any user would be able to write a script to give commands to a scriptable program which would use the Accessibility API to access the interface elements of any program." To see the significance of this, just take out the middle terms, and what have you got? Any user can write a script that can access the interface elements of any program. Any user can script an unscriptable program, using AppleScript! You wouldn't need any special macro program, because AppleScript itself, which is already on your computer, would become a macro language.

Of course, for this to work, there has to be that "middle term" - the go-between, the application that receives AppleScript commands and talks to the Accessibility API. That application is called System Events. It's on your computer right now, in /System/Library/Core Services.

But here, he mentions only the accessibility API, which gives "GUI scripting", right?

What other practical use cases are there for System Events scripting? Would you have a simple example?

And thank you for the book reference. I'll be putting it either on my BD list or on my Xmas list :)

Jean-Christophe 


2551phil
 

On 20 Oct 2017, at 23:10, Jean-Christophe Helary <jean.christophe.helary@gmail.com> wrote:
Bill mentioned (Matt Neuburg's TidBits article)…And thank you for the book reference. I'll be putting it either on my BD list or on my Xmas list :)nn
Same author.

What other practical use cases are there for System Events scripting?
Again, I can only refer you to the Dictionary and reiterate that, in this regard, it’s like any other app. What practical use is there for scripting the Finder, or Numbers? Doesn’t it depend on what they expose in their Dictionaries? Same is true of System Events.

When you look at the Dictionary, you’ll see a lot of overlap with the Finder, but if given the choice between the two, I’d go with System Events. However, (especially now we have the ASObjC bridge), I’d almost always try to find another way for just about anything if possible cos neither are that quick or that reliable.

Would you have a simple example?
Probably the thing I, personally, use System Events the most for is in Script Debugger to see what properties, objects and classes of other apps I can manipulate. Thus

tell application "System Events"
#~-- your code goes here...~#
end tell

is a common go-to I use, where I never fill in the ‘your code goes here’ part or even compile the script. I just leave the cursor on the first line within “System Events” and use SD’s live inspector to browse the goodies.

I think there’s a video on the latenightsw site showing how to do this if you’re not familiar with what I’m talking about.


Best


Phil
@sqwarq


2551phil
 


On 21 Oct 2017, at 01:24, Steve Mills <sjmills@...> wrote:

crosspost

You’re twisting the concept. Anyone on an AppleScript mailing list should expect to get posts about AppleScript. Being on more than one list of the same subject and getting duplicates of the same message isn’t “crossposting”. 

Crossposting means sending the same message to several diverse groups. Hence “cross”…both in terms of crossing subject-specific content and in terms of audience reaction…

If you object to getting messages about AppleScript in an AppleScript list you’re subscribed to, either complain that the message is off-topic or, if you get no joy, unsubscribe from a list that doesn’t cover your interests.



Best


Phil
@sqwarq


 

Phil,

Thanks for posting this.  This is a huge tip!
For those that don't have SD6, or, like me, not sure what Phil is referring to, here's a screen shot of the lower Inspector Panel of SD6, after I have entered the simple script below:


Here is another screenshot where I have expanded the "UI elements" list:


Best Regards,

Jim Underwood
aka JMichaelTX


From: AppleScript-Users <applescript-users-bounces+jmichael=apoemail.us@...> on behalf of 2551phil <2551phil@...>
Date: Friday, October 20, 2017 at 12:44 PM
To: "applescript@apple-dev.groups.io" <applescript@apple-dev.groups.io>, "ASUL (AppleScript)" <applescript-users@...>
Subject: Re: [applescript] What is "system events" ?

tell application "System Events"
#~-- your code goes here...~#
end tell

is a common go-to I use, where I never fill in the ‘your code goes here’ part or even compile the script. I just leave the cursor on the first line within “System Events” and use SD’s live inspector to browse the goodies.


2551phil
 

You’re confusing crossposting with cross-subscribing. In both lists, his posts were on topic. The fact that you got duplicates is your problem.




On 21 Oct 2017, at 04:18, Steve Mills <sjmills@...> wrote:

On Oct 20, 2017, at 02:11 PM, 2551phil <2551phil@...> wrote:


On 21 Oct 2017, at 01:24, Steve Mills <sjmills@...> wrote:
crosspost

You’re twisting the concept. Anyone on an AppleScript mailing list should expect to get posts about AppleScript. Being on more than one list of the same subject and getting duplicates of the same message isn’t “crossposting”. 

Crossposting means sending the same message to several diverse groups. Hence “cross”…both in terms of crossing subject-specific content and in terms of audience reaction…

If you object to getting messages about AppleScript in an AppleScript list you’re subscribed to, either complain that the message is off-topic or, if you get no joy, unsubscribe from a list that doesn’t cover your interests.

You are wrong. He DID crosspost to both lists from the same original message. He sent one message to both groups. That's crossposting. Two completely different lists run by two completely different entities. That's crossposting. I'm replying to all to show you how annoying it is. I only replied to one because *I* didn't want my reply to be crossposted. But now I'm crossposting to illustrate how annoying it is.

Sent from iCloud's ridiculous UI, so, sorry about the formatting

 
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (applescript-users@...)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/applescript-users/2551phil%40gmail.com
Archives: http://lists.apple.com/archives/applescript-users

This email sent to 2551phil@...


2551phil
 

Note that you can do the same trick with any other app, too, not just System Events; i.e., see a live view of whatever app’s properties, classes, etc. 

The live inspector view, along with the variables view and SD’s dictionary viewer, are really what make SD worthwhile for me. I rarely have need to actually step into the debugger itself thanks to these.


Best


Phil
@sqwarq


On 21 Oct 2017, at 03:58, JMichaelTX <JMichael@...> wrote:

Phil,

Thanks for posting this.  This is a huge tip!
For those that don't have SD6, or, like me, not sure what Phil is referring to, here's a screen shot of the lower Inspector Panel of SD6, after I have entered the simple script below:

<86B7B648-8F29-47A3-B65C-CC510BF7DBD6.png>

Here is another screenshot where I have expanded the "UI elements" list:

<2C57F2BE-98A6-4CB0-8697-D2C9411066FD.png>

Best Regards,

Jim Underwood
aka JMichaelTX


From: AppleScript-Users <applescript-users-bounces+jmichael=apoemail.us@...> on behalf of 2551phil <2551phil@...>
Date: Friday, October 20, 2017 at 12:44 PM
To: "applescript@apple-dev.groups.io" <applescript@apple-dev.groups.io>, "ASUL (AppleScript)" <applescript-users@...>
Subject: Re: [applescript] What is "system events" ?

tell application "System Events"
#~-- your code goes here...~#
end tell

is a common go-to I use, where I never fill in the ‘your code goes here’ part or even compile the script. I just leave the cursor on the first line within “System Events” and use SD’s live inspector to browse the goodies.


Robert Poland
 

If my receiving duplicate messages is my fault, How do I avoid them?

Also how do we eliminate duplicate and triplicate footers?

On Oct 20, 2017, at 3:20 PM, 2551phil <2551phil@...> wrote:

You’re confusing crossposting with cross-subscribing. In both lists, his posts were on topic. The fact that you got duplicates is your problem.




On 21 Oct 2017, at 04:18, Steve Mills <sjmills@...> wrote:

On Oct 20, 2017, at 02:11 PM, 2551phil <2551phil@...> wrote:


On 21 Oct 2017, at 01:24, Steve Mills <sjmills@...> wrote:
crosspost

You’re twisting the concept. Anyone on an AppleScript mailing list should expect to get posts about AppleScript. Being on more than one list of the same subject and getting duplicates of the same message isn’t “crossposting”. 

Crossposting means sending the same message to several diverse groups. Hence “cross”…both in terms of crossing subject-specific content and in terms of audience reaction…

If you object to getting messages about AppleScript in an AppleScript list you’re subscribed to, either complain that the message is off-topic or, if you get no joy, unsubscribe from a list that doesn’t cover your interests.

You are wrong. He DID crosspost to both lists from the same original message. He sent one message to both groups. That's crossposting. Two completely different lists run by two completely different entities. That's crossposting. I'm replying to all to show you how annoying it is. I only replied to one because *I* didn't want my reply to be crossposted. But now I'm crossposting to illustrate how annoying it is.

Sent from iCloud's ridiculous UI, so, sorry about the formatting

 
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (applescript-users@...)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/applescript-users/2551phil%40gmail.com
Archives: http://lists.apple.com/archives/applescript-users

This email sent to 2551phil@...


Robert Poland
Fort Collins, CO


Jean-Christophe Helary <jean.christophe.helary@...>
 

Thank you all for the replies. I have a much cleared idea of what the thing is intended for!

And, yes, ASObjC. I'll need to bite the bullet eventually...

Jean-Christophe

On Oct 21, 2017, at 2:44, 2551phil <2551phil@gmail.com> wrote:


On 20 Oct 2017, at 23:10, Jean-Christophe Helary <jean.christophe.helary@gmail.com> wrote:
Bill mentioned (Matt Neuburg's TidBits article)…And thank you for the book reference. I'll be putting it either on my BD list or on my Xmas list :)nn
Same author.

What other practical use cases are there for System Events scripting?
Again, I can only refer you to the Dictionary and reiterate that, in this regard, it’s like any other app. What practical use is there for scripting the Finder, or Numbers? Doesn’t it depend on what they expose in their Dictionaries? Same is true of System Events.

When you look at the Dictionary, you’ll see a lot of overlap with the Finder, but if given the choice between the two, I’d go with System Events. However, (especially now we have the ASObjC bridge), I’d almost always try to find another way for just about anything if possible cos neither are that quick or that reliable.

Would you have a simple example?
Probably the thing I, personally, use System Events the most for is in Script Debugger to see what properties, objects and classes of other apps I can manipulate. Thus

tell application "System Events"
#~-- your code goes here...~#
end tell

is a common go-to I use, where I never fill in the ‘your code goes here’ part or even compile the script. I just leave the cursor on the first line within “System Events” and use SD’s live inspector to browse the goodies.

I think there’s a video on the latenightsw site showing how to do this if you’re not familiar with what I’m talking about.


Best


Phil


 

Jean-Christophe,

You have made some good points about the "System Events" app (which it really is not).  😉

I have come to think of SE as the AppleScript Swiss Army Knife -- it is a great utility for doing many, often unrelated, things.
I suspect that the AppleScript "old timers" know it like the back of their hand, and don't give much thought to it.  

But to those of us still learning AppleScript (which I still am), it has not been clear.  Like the Swiss Army Knife, some of the tools are fairly obvious, while others are not.  And like any tool, understanding a tool's features, and knowing how to use it, and what use cases it is good/best for, are two very different things.

Thanks for asking this question.

And thanks to everyone who has replied with a helpful answer.  I've learned a lot from you today.  😄

Best Regards,

Jim Underwood
aka JMichaelTX

P.S.  So as to not upset the sensitive among you, I am bcc this to the apple-dev.groups.io/g/applescript 

From: Jean-Christophe Helary <jean.christophe.helary@...>
Date: Friday, October 20, 2017 at 7:05 PM
To: "ASUL (AppleScript)" <applescript-users@...>
Subject: Re: What is "system events" ?

Ok, I had the idea that it was mostly UI scripting, but sometimes it would do something else. Indeed, the dictionary covers a huge lot of totally unrelated areas of specialization.

So I guess I just need to remind myself that "System Events" is a misnomer and call that "Headless Applications Bundle", which is much less sexy, but more indicative of what the thing really does.

Thank you again all who have replied.

Jean-Christophe


 

On Fri, Oct 20, 2017 at 02:09 am, Bill Cheeseman wrote:
There are links and a lot of commentary on my website: http://pfiddlesoft.com. Look at the UI Browser section first, then maybe the frameworks page.
Bill, thanks for the reference, but I was unable to find any references to "System Events" on either of those sections.  I did a browser search for "system", and it didn't find anything.  Did I miss them?

If you could provide the actual links here, I'd love to include them in the new AppleScript Wiki article we are writing.


Jean-Christophe Helary <jean.christophe.helary@...>
 



On Oct 22, 2017, at 9:04, JMichaelTX <JMichael@...> wrote:

On Fri, Oct 20, 2017 at 02:09 am, Bill Cheeseman wrote:
There are links and a lot of commentary on my website: http://pfiddlesoft.com. Look at the UI Browser section first, then maybe the frameworks page.
Bill, thanks for the reference, but I was unable to find any references to "System Events" on either of those sections.  I did a browser search for "system", and it didn't find anything.  Did I miss them?

The tidbits article written by Matt Neuburg is in my opinion the most important as far as understanding what System Events is.

Jean-Christophe 


Bill Cheeseman
 

My website, and my UI Browser product, are all about GUI Scripting. Which, as you now know, uses the Processes Suite of System Events. You'll find the most detail here: <http://pfiddlesoft.com/uibrowser/support.html>.

On Oct 21, 2017, at 8:04 PM, JMichaelTX <JMichael@...> wrote:

On Fri, Oct 20, 2017 at 02:09 am, Bill Cheeseman wrote:
There are links and a lot of commentary on my website: http://pfiddlesoft.com. Look at the UI Browser section first, then maybe the frameworks page.
Bill, thanks for the reference, but I was unable to find any references to "System Events" on either of those sections.  I did a browser search for "system", and it didn't find anything.  Did I miss them?

If you could provide the actual links here, I'd love to include them in the new AppleScript Wiki article we are writing.



-- 

Bill Cheeseman - wjcheeseman@...


Bill Cheeseman
 

As far as I know, the most thorough writeup of GUI Scripting specifically is chapter 28 of the book I co-wrote with Sal Soghoian, "AppleScript 1-2-3", part of the Apple Training Series, published by Peachpit Press in 2009.

On Oct 21, 2017, at 8:49 PM, Jean-Christophe Helary <jean.christophe.helary@...> wrote:

The tidbits article written by Matt Neuburg is in my opinion the most important as far as understanding what System Events is.

-- 

Bill Cheeseman - wjcheeseman@...


Jean-Christophe Helary <jean.christophe.helary@...>
 

Thank you.
I mentioned the article because it was available online form your site.

Jean-Christophe 

On Oct 22, 2017, at 16:37, Bill Cheeseman <wjcheeseman@...> wrote:

As far as I know, the most thorough writeup of GUI Scripting specifically is chapter 28 of the book I co-wrote with Sal Soghoian, "AppleScript 1-2-3", part of the Apple Training Series, published by Peachpit Press in 2009.

On Oct 21, 2017, at 8:49 PM, Jean-Christophe Helary <jean.christophe.helary@...> wrote:

The tidbits article written by Matt Neuburg is in my opinion the most important as far as understanding what System Events is.

-- 

Bill Cheeseman - wjcheeseman@...



Jean-Christophe Helary <jean.christophe.helary@...>
 



On Oct 22, 2017, at 9:49, Jean-Christophe Helary <jean.christophe.helary@...> wrote:

On Fri, Oct 20, 2017 at 02:09 am, Bill Cheeseman wrote:
There are links and a lot of commentary on my website: http://pfiddlesoft.com. Look at the UI Browser section first, then maybe the frameworks page.
Bill, thanks for the reference, but I was unable to find any references to "System Events" on either of those sections.  I did a browser search for "system", and it didn't find anything.  Did I miss them?

The tidbits article written by Matt Neuburg is in my opinion the most important as far as understanding what System Events is.

The tidbits article was super well hidden in the pages:

http://pfiddlesoft.com → [UI Browser] → (above the screenshot) [Reading] → [PreFab UI Browser 2.0 Better Than Ever]

Et voilà !

Bill, maybe you should make it a way that the [Reading] section is easier to see.

Jean-Christophe