Looking for Advanced Apple Scripting Resources

I cam across the following post by @Camelot and I was wondering where I can go to learn about the code provided and look at the documentation.

AppleScript for Message Received - Apple Community


Code (And post) In question: (From @Camelot)


using terms from application "Messages"


on message receivedtheMessagefromtheBuddyfortheChat



-- YOUR CODE HERE


end message received


on received text invitationtheTextfromtheBuddyfortheChat


accepttheChat

end received text invitation


on received audio invitationtheTextfromtheBuddyfortheChat


accepttheChat

end received audio invitation


on received video invitationtheTextfromtheBuddyfortheChat


accepttheChat

end received video invitation


on received file transfer invitationtheFileTransfer


accepttheFileTransfer

end received file transfer invitation


on buddy authorization requestedtheRequest


accepttheRequest

end buddy authorization requested



# The following are unused but need to be defined to avoid an error


on message senttheMessagefortheChat


end message sent



on chat room message receivedtheMessagefromtheBuddyfortheChat


end chat room message received


on active chat message receivedtheMessage


end active chat message received


on addressed chat room message receivedtheMessagefromtheBuddyfortheChat


end addressed chat room message received


on addressed message receivedtheMessagefromtheBuddyfortheChat


end addressed message received


on av chat started


end av chat started


on av chat ended


end av chat ended


on login finishedfortheService


end login finished


on logout finishedfortheService


end logout finished


on buddy became availabletheBuddy


end buddy became available


on buddy became unavailabletheBuddy


end buddy became unavailable


on completed file transfer


end completed file transfer

end using terms from


The rest of the code is irrelevant for your needs, but is required to prevent Messages.app from choking on your script not knowing how to deal with events.


Next, save your script in ~/Library/Application Scripts/com.apple.iChat


It will now appear in Messages' preferences, under the 'AppleScript handler' option.


Now, for any event, Messages will invoke the appropriate handler in your script.


--End of Post--

Mac mini, macOS 13.5

Posted on Dec 8, 2023 3:13 PM

Reply
Question marked as Top-ranking reply

Posted on Dec 9, 2023 3:14 AM

In addition to HWTech's link, certain applications may have AppleScript scripting dictionaries that outline how you can access or control those applications using AppleScript. Launch Apple's Script Editor and on its File menu, you will see Open Dictionary… The applications listed there have AppleScript support and those missing do not. The scripting dictionaries can also change their contents as newer applications are introduced resulting in broken AppleScript code. Beware of that.


Script Editor User Guide for Mac - Apple Support


An online source of AppleScript questions and coded solutions can be found at the new :macScripter.net or the forum on LateNightSoftware's site.


However, AppleScript is a very old language that lacks most of the features one encounters in modern scripting languages and depending on your goals, may not be the right language choice for more complicated solutions.

4 replies
Question marked as Top-ranking reply

Dec 9, 2023 3:14 AM in response to Andy-rue

In addition to HWTech's link, certain applications may have AppleScript scripting dictionaries that outline how you can access or control those applications using AppleScript. Launch Apple's Script Editor and on its File menu, you will see Open Dictionary… The applications listed there have AppleScript support and those missing do not. The scripting dictionaries can also change their contents as newer applications are introduced resulting in broken AppleScript code. Beware of that.


Script Editor User Guide for Mac - Apple Support


An online source of AppleScript questions and coded solutions can be found at the new :macScripter.net or the forum on LateNightSoftware's site.


However, AppleScript is a very old language that lacks most of the features one encounters in modern scripting languages and depending on your goals, may not be the right language choice for more complicated solutions.

Dec 9, 2023 5:32 PM in response to HWTech

Im looking for information on why all these lines are needed, what they accomplish, what tasks do they run. Most of these commands are not found in the messages dictionary within the AppleScript editor app nor on Apple’s online documentation in the link you provided (though that is very helpful and Ill be reading all of that, so Thank you :D)

Dec 15, 2023 5:27 PM in response to Andy-rue

If I ever used AppleScript, it would have been one time decades ago. Here is another article which contains a tutorial introduction to AppleScript which may help to explain some things, but this one is very very old.

https://applescriptlibrary.files.wordpress.com/2013/11/applescript-language-guide-1-3-7-os-8-5-1.pdf


Maybe you can find a newer tutorial or book to get you started.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Looking for Advanced Apple Scripting Resources

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.