Skip to content

Instantly share code, notes, and snippets.

@jqtruong
Created July 23, 2013 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jqtruong/6064851 to your computer and use it in GitHub Desktop.
Save jqtruong/6064851 to your computer and use it in GitHub Desktop.
When i feel like taking a break to watch a video but now ads are everywhere, thought of this neat elisp script to turn off the volume for a specified number of seconds (otherwise defaults to 30) and message me when the time's up on a Mac OS X, using osascript... now if there was a way to switch back to my browser :) i'll try that on stumpwm!
(defun jqt/skip-ads (&optional seconds)
"SECONDS default to 30"
(interactive "p")
(let* ((seconds (number-to-string (or seconds 30)))
(command "osascript -e 'output volume of (get volume settings)'")
(output (shell-command-to-string command))
(current-volume (replace-regexp-in-string "[\s\n]" "" output))
(set-volume-command "osascript -e 'set volume output volume %s'"))
(shell-command (format set-volume-command 0))
(message "Ads stink! Turned volume (was at level %s) off for %s seconds..." current-volume seconds)
(run-at-time (concat seconds " sec") nil
(lambda (v cmd)
(shell-command (format cmd v))
(message "Ads should be done now... phew! Turned volume back up to %s." v))
current-volume set-volume-command)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment