Script that only works on set computers

I have a script that I want to restrict to be used only on certain machines, ideally specified by computer name
Anyone know how I can get this running
:confused:

Hi,

to check for the name of the computer try this


property validList : {"computer_1", "computer_2"}

if computer name of (system info) is not in validList then
	display dialog "This computer is not authorized to run this script" buttons {"QUIT"} default button 1 with icon stop
	return
end if

But computer names can be changed easily. It’s more robust to check for the primary ethernet address

 if primary Ethernet address of (system info) is not in validList then
.

Thanks for that, all machines are on a managed network in a university, so on certain users have access to change name, but thanks for the heads up.
Would it be possible to put the machine names authorized into a list in say a textedit file for it to refer to, I have a few of them.
With my limited use so far I have referred to files for other things and settings, presuming it would have to be comma-delimited.
Thanks again:/

assuming the computer names or ethernet addresses are in a plain text file MacRoman encoded, one entry per line.


set validList to paragraphs of (read file "MacHD:path:to:file.txt")

if computer name of (system info) is not in validList then
	display dialog "This computer is not authorized to run this script" buttons {"QUIT"} default button 1 with icon stop
	return
end if

Great stuff thanks for this. Decided to go with embedding the machine names in the script in the end, less files to transfer onto each machine.

One other thought on this, the computer names that I need to authorise all have a letter as a prefix ie A13425, they are all 6 digits in total, rather than putting all of them in the script is there a way of doing it wildcards??
have tried ones below but they do not work. Any ideas?:confused:


property validList : {β€œA*****”}



property validList : {β€œA-----”}


There are no wildcards in AppleScript but you can do it with


if theString starts with "A" and length of theString is 6 then
	 -- do something
end if