Skip to content

Instantly share code, notes, and snippets.

@mbierman
Last active October 14, 2016 18:51
Show Gist options
  • Select an option

  • Save mbierman/58e93be02880305137691512a05dc2de to your computer and use it in GitHub Desktop.

Select an option

Save mbierman/58e93be02880305137691512a05dc2de to your computer and use it in GitHub Desktop.
AppleScript to fade audio , pause music, and restore volume
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
@mbierman
Copy link
Author

mbierman commented Oct 6, 2016

osascript -e "set volume without output muted"
osascript -e "set volume with output muted"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment