On the remote computer, save this following AppleScript code in a new Script Editor.App document (Script Editor.App is located here... /Applications/Utilities/Script Editor.app) as a "Stay Open" application. Before saving this document as an application, make sure you enter your current external IP address and the email address in the first two lines of the code.
To summarize what the AppleScript code does is simply... Every 15 minutes it checks your current external IP address against the IP address you set in the first line of the code. If those two IP addresses are not the same, the script will go ahead and send a new email (to the email address you set in the second line of the code) with the new updated external IP address.
Then just like opening any other application in Finder, double-clicking your newly created app will run the new app.
property ipAddress : "123.456.7.89" -- Insert Current External IP Address (Set Only Once)
property toRecipient : "[email protected]" --Email To Get IP Has Changed Messages
on idle
set theIP to do shell script "curl ifconfig.co"
if theIP is not equal to ipAddress then
tell application "Mail"
set newEmail to (make new outgoing message)
set content of newEmail to theIP
set subject of newEmail to "IP Address Has Changed"
tell newEmail
make new to recipient with properties {address:toRecipient}
send
end tell
end tell
set ipAddress to theIP
end if
return (15 * minutes) -- Waits 15 min. to check IP again
end idle
Don't forget to add this new AppleScript application, in System Preferences, to the list of apps allowed to control your computer.
UPDATE
Although the above script seems to work, after several runs and minor changes to the code for testing purposes, I decided to create an alternate solution. Because of the new security settings in macOS Mojave and AppleScript's inability to reliably update and maintain its Global and Persistent property values across runs, I feel this alternate solution is much more reliable.
Step 1: On the remote computer, in Script Editor.app, save this AppleScript code as a .scpt file and name it "Get Current External IP.scpt"
Be sure you change the value of property toRecipient
to your email address
property ipAddress : "1.1.1.1" -- Not Necessary To Set
property toRecipient : "[email protected]" --Email To Get IP Has Changed Messages
set emailIsRunning to application "Mail" is running -- Checks If Mail Is Running
try
set lastLoggedIP to readFile()
set theIP to do shell script "curl ifconfig.co"
if theIP is not equal to lastLoggedIP then
sendNewEmail()
writeToTheFile()
end if
on error errMsg number errNum
if errNum is -43 then -- The Error If File For readFile() Doesn't Exist Yet
set theIP to do shell script "curl ifconfig.co"
if theIP is not equal to ipAddress then
sendNewEmail()
writeToTheFile() -- Creates The "/private/tmp/IP Logger.txt" File
end if
else
activate
display dialog "An error has occurred:" & return & errMsg & " " & errNum giving up after 10
end if
end try
delay 20 -- Allows For Completion Of Any Incoming Or Outgoing Mail Messages
if not emailIsRunning then quit application "Mail" -- Quits Mail If Wasn't Already Running
to sendNewEmail() -- Sends New Email Whenever IP Changes
set theIP to do shell script "curl ifconfig.co"
tell application "Mail"
set newEmail to (make new outgoing message)
set content of newEmail to theIP
set subject of newEmail to "IP Address Has Changed"
tell newEmail
make new to recipient with properties {address:toRecipient}
send
end tell
end tell
set ipAddress to theIP
end sendNewEmail
on readFile() -- Reads IP Logger.txt To Check For IP Changes
set theFile1 to alias "private:tmp:IP Logger.txt"
set lastLoggedIP to last item of (read theFile1 as text using delimiter linefeed)
end readFile
on writeToTheFile() -- Logs Every IP Change To File
set theIP to do shell script "curl ifconfig.co"
set theFile to "/private/tmp/IP Logger.txt"
set theText to theIP
try
set writeToFile to open for access theFile with write permission
write theText & linefeed to writeToFile as text starting at eof
close access theFile
on error errMsg number errNum
close access theFile
set writeToFile to open for access theFile with write permission
write theText & linefeed to writeToFile as text starting at eof
close access theFile
end try
end writeToTheFile
Step 2: On the remote computer, in Script Editor.app, save this following AppleScript code as a "stay open" application file. I named it "IP Changed Email Notify.app".
If you did not save "Get Current External IP.scpt" to your Documents folder in Step 1 from above, then you must set its location in property currentExternalIP
in the following code.
property currentExternalIP : alias ((path to documents folder as text) & "Get Current External IP.scpt")
run script currentExternalIP
on idle
run script currentExternalIP
return (15 * minutes)
end idle
The first time you run the new stay open AppleScript app (IP Changed Email Notify.app) from outside of Script Editor.app, you will be presented with this following dialog...
Just click "OK" and since all of the work is actually being done by "Get Current External IP.scpt" there should be no more future dialogs or alerts to deal with.
Step 3: (OPTIONAL) On the remote computer, add this newly created AppleScript application (IP Changed Email Notify.app) to your "Login Items" in the Users And Groups System Preferences panel. Now every time the computer restarts, IP Changed Email Notify.app will run automatically and any time the external IP address of that computer changes, you will get an email notification.