AppleScript is a computer language that Apple made. Using this language you can control various applications. Although limited, in some cases you can order your Mac to do repetitive tasks that are tedious.
The reason was easy. I wanted to wake up to music. Of course I could have bought an application to do this but why do this when you have AppleScript. One more thing I wanted was to listen to music until I fell asleep.
All you need to do this is to copy the code below into the AppleScript Editor. Then it will look like this.
on run # Gets the wake up time from the user. set targetTime to text returned of (display dialog "Enter the time you want to wake up:" default answer "" & (current date)) ## Corrects the date if (current date) > (date targetTime) then set subTargetTime to (date targetTime) + (24 * hours) else set subTargetTime to (date targetTime) end if display dialog "See you at " &(subTargetTime as string) & "." # display dialog "Delay " & (subTargetTime - (current date) ) & " seconds." # Turn on the music. tell application "iTunes" set sound volume to 30 play end tell # Turn off the music after 30 minutes. delay 60 * 30 tell application "iTunes" pause end tell # Turn on the music at the alarm time. delay subTargetTime - (current date) tell application "iTunes" set sound volume to 70 play end tell # display dialog "Finished" end run
After copying the code to the AppleScript editor, if you press Run (in the AppleScript Editor) then you will get this window.
Then music will start playing and after 30 minutes it will turn off. Then it will play the music once again at the set alarm time.
But it is tedious to always open the apple script and pressing Run. If you make the script into an application you will just need to run the application.
It is easy to make an application from AppleScript. In the AppleScript Editor goto File->Save as… And then in the File Format, change it to Application.
Then the script will be changed into a program. If you run the program it will directly show the alarm time window.
When you run the program it will be shown in the Dock. So if you want to turn the alarm off choose the program and quit.
If you don’t want to listen to music when you sleep, just comment out the portion that turns on the music and turns off the music after 30 minutes by adding “#”. Of course you can also just delete according lines.
If you edit the script a little bit you can listen to different music when you sleep and wake up. Make two iTunes playlists. One for sleeping and one for waking up. Then you can order apple script to play the according playlist. If you google “iTunes applescript” you can find the commands for it.