Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write Applescript that will give me an hourly popup alert [closed]

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

like image 313
Kramer Avatar asked Sep 15 '10 14:09

Kramer


People also ask

What is replacing AppleScript?

Using Swift.

Does Apple still use AppleScript?

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.

What language does AppleScript use?

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.


1 Answers

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.

like image 58
Jerry Stratton Avatar answered Sep 22 '22 21:09

Jerry Stratton