I am wondering how to have a popup alert on my computer (Mac OS X) every hour. I figured writing this in Applescript would be pretty simple but I have no Applescript experience. Thanks
Using Swift.
AppleScript is a scripting language created by Apple Inc. that facilitates automated control over scriptable Mac applications. First introduced in System 7, it is currently included in all versions of macOS as part of a package of system automation tools.
AppleScript scripts are composed, by motivated users like yourself, in AppleScript, an English-like language containing many of the verbs, nouns, adjectives, articles and other English language elements we use every day.
The basic handler for doing things on a regular basis in AppleScript is the idle handler.
on idle
display dialog "Go back to work" buttons "Work Harder" default button "Work Harder"
return 3600
end idle
This script will pop up a dialog box when you start the application and then every 3,600 seconds after pressing the button. Whatever number the idle handler returns will be the number of seconds before the next idle event is triggered.
If you want it to be on the half-hour and not every sixty minutes, you'd want the idle script to return a different number of seconds, perhaps 60, and then check to see if you're at the right part of the hour.
on idle
if the minutes of the (current date) is 30 then
display dialog "Go back to work" buttons "Work Harder" default button "Work Harder"
end if
return 60
end idle
This will only display the dialog at half past. (Like Unix, AppleScript’s concept of the current date includes the current time.)
In each case, you want to save in AppleScript Editor as “Application” and “Stay Open” in order to have it respond to idle events instead of just quitting after running. And you can add the application to your list of “Login Items” in the “Accounts” system preference to make it run automatically when you log in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With