Contribute
Register

Solving the audio pop problem with an AppleScript

Status
Not open for further replies.

isw

Joined
Nov 15, 2012
Messages
3
Motherboard
GIGABYTE GA-Z77N-WIFI
CPU
i5 2500K
Graphics
HD 3000
Mac
  1. 0
Classic Mac
  1. 0
Mobile Phone
  1. 0
In some Macs, the audio subsystem is powered down when not in use (evidently to conserve battery or otherwise minimize power consumption). This has the effect of causing a delay whenever audio is called for after a period of time, and making a "pop" as the amplifier is powered up.

One solution to this is to choose a system definition which never powers down the audio system. Since I want to run a dual-monitor setup, I chose "mini 5,1" which unfortunately does shut the audio down.

I found references to an audio "pop-stopper" (anti-pop 1.0.2), but I don't like using "black boxes" unless I have to; I like to be able to tweak things to suit myself. But the way it deals with the problem was clever, so I decided to do a little AppleScript that does the same thing.

Here it is:

--

on run -- this happens one time, when the script is invoked
say "Audio keep-alive starting" -- this isn't necessary, but shows that the script has started
end run
on idle -- this is the loop where the script spends its day
say " " -- this is just silence, but it keeps that audio system alive
return 30 -- wait this many seconds before looping (you may need a different value)
end idle
on quit -- this happens once, when the script receives a"Quit" command
-- put something here that you want to run at shutdown
continue quit
end quit

--

If you're not familiar with AppleScript (but you should be; it's one of the things that really differentiates Macs from "ordinary" computers), here's how to get it going:

1) Open AppleScript Editor, and copy-paste the text between the dashes above into it.

2) Click "Compile" at the top; the script should change its appearance, and show no errors.

3) Click File/Save as ...

4) At the top of the pane, pick a good name (I used "Audio Keep-alive")

5) At the bottom, select File Format and choose Application, and click the box for "Stay open after run handler"

6) Now click Save, and put it somewhere where you can find it later.

7) Open System Preferences/Users & Groups, choose your account, and click "Login Items.

8) Click the "+", navigate to your new script, and add it to the list. Hide it or not, as you please.

Now, whenever you log in, that script will run, and stay running, saying "nothing" every 30 seconds, keeping the audio system "live".

There is another nice advantage to doing things this way, too.

Although it's easy to cause any app to run at startup just by adding it to that "Login items" list, it's really pretty difficult to cause something to run at shutdown. But if you just add the appropriate AppleScript commands to this keep-alive script, between "on quit" and "continue quit", they will be executed automatically whenever you log out or shut down.
 
Does using this mean you have an icon in the Dock for it all the time though?
 
Add this to the info.plist file in the app you created (right click the app and "show Package contents"), and the AppleScript shouldn't show up in the Dock:

<key>NSUIElement</key>
<string>1</string>
 
Status
Not open for further replies.
Back
Top