Create AppleScript app that runs only under a specific account?

Is it possible to create an AppleScript app that will run only on a system logged in to a specific Apple ID? In other words, if I’m commissioned to write a script by someone with an Apple ID bartlebythescriviner@mac.com, can I create an app that will run only on a system in which that ID is active?

You could check for the current user’s name in your script, for instance. Eg. by calling the Terminal command: echo $USER
Or: whoami

There may be similar commands to query the currently logged-in iCloud user. Try to google that.

However, anyone could easily modify your script and remove this check by opening it in Script Editor.

I know of no more secure method, sorry.

Thank you, Thomas. I haven’t found a command to query the currently logged-in iCloud user, but it may exist. If it does, then it should be possible to save a script as run-only so that a user couldn’t modify it.

This isn’t urgent, but I hope it might be useful if it’s possible.

A user named grg at StackOverflow answered this question. The command needed is:

/usr/libexec/PlistBuddy -c “print :Accounts:0:AccountID” ~/Library/Preferences/MobileMeAccounts.plist

If you test the result of this against a specific iCloud account string (everything to the left of the at-sign, because the domain can be iCloud.com or Mac.com or Me.com), and export the script as read-only, then you can create a script that will run only for the user with the current iCloud account.

because the domain can be iCloud.com or Mac.com or Me.com

One can be signed into iCloud using any valid email address, which includes domains other than those you list.