Last active
October 14, 2016 18:51
-
-
Save mbierman/58e93be02880305137691512a05dc2de to your computer and use it in GitHub Desktop.
AppleScript to fade audio , pause music, and restore volume
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| set input to text returned of (display dialog "How many minutes should I play music for?" default answer "90") | |
| delay input * 60 | |
| --- fade volume | |
| tell application "iTunes" | |
| set currentvolume to the sound volume | |
| repeat with i from currentvolume to 0 by -2 | |
| set the sound volume to i | |
| delay 0.5 | |
| end repeat | |
| pause | |
| delay 2 | |
| --- restore volume to original setting | |
| set sound volume to currentvolume | |
| -- display dialog "Volume is: " & ovol & " " & currentvolume | |
| end tell | |
| tell application "Finder" | |
| activate | |
| with timeout of 31 seconds | |
| set r to display dialog "BigMac going to sleep" buttons {"Cancel", "Sleep now"} default button "Sleep now" giving up after 30 -- seconds | |
| if r's gave up or r's button returned is not "Cancel" then | |
| -- display alert "Sleep now was clicked" | |
| tell application "Finder" to sleep | |
| end if | |
| end timeout | |
| return 30 -- seconds | |
| end tell |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
osascript -e "set volume without output muted"
osascript -e "set volume with output muted"