Created
          May 23, 2024 19:49 
        
      - 
      
- 
        Save OhTerryTorres/f76af192d2098111e2162b6da5b49608 to your computer and use it in GitHub Desktop. 
    AppleScript to fade out 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 minutesBeforeFadeOutBeginsPrompt to display dialog "Minutes before fade out begins?" default answer "1" with icon note buttons {"Cancel", "Continue"} default button "Continue" | |
| set fadeOutIntervalPrompt to display dialog "Fade out interval? (in seconds)" default answer "10" with icon note buttons {"Cancel", "Continue"} default button "Continue" | |
| set minutesBeforeFadeOutBegins to (text returned of minutesBeforeFadeOutBeginsPrompt) as number | |
| set fadeOutInterval to (text returned of fadeOutIntervalPrompt) as number | |
| set fadeOutStartCountdown to minutesBeforeFadeOutBegins * 60 | |
| set fadeOutStartProgress to 0 | |
| set progress total steps to fadeOutStartCountdown | |
| set progress description to "Countdown to fade out..." | |
| repeat | |
| set fadeOutStartProgress to (fadeOutStartProgress + 1) | |
| set progress completed steps to fadeOutStartProgress | |
| delay 1 | |
| if (fadeOutStartProgress) ≥ fadeOutStartCountdown then | |
| exit repeat | |
| end if | |
| end repeat | |
| set progress total steps to 100 | |
| set newVolume to output volume of (get volume settings) | |
| repeat | |
| if output volume of (get volume settings) ≠ newVolume then | |
| log "reseting volume" | |
| set newVolume to (output volume of (get volume settings)) - 1 | |
| end if | |
| set newVolume to (newVolume - 1) | |
| set volume output volume newVolume | |
| if (newVolume) ≤ 0 then | |
| exit repeat | |
| end if | |
| set fadeOutIntervalProgress to fadeOutInterval | |
| repeat | |
| set fadeOutIntervalProgress to (fadeOutIntervalProgress - 1) | |
| set progress description to "Fading out. Current Volume: " & output volume of (get volume settings) & "/100%" | |
| set progress completed steps to output volume of (get volume settings) | |
| set progress additional description to fadeOutIntervalProgress | |
| delay 1 | |
| if (fadeOutIntervalProgress) ≤ 0 then | |
| exit repeat | |
| end if | |
| end repeat | |
| end repeat | |
| set progress description to "Faded out." | |
| delay 1 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment