Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Make a more obvious low battery warning' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Make a more obvious low battery warning
Authored by: mark hunte on Feb 26, '11 05:55:06AM
You can play sounds headless (no GUI app) and its always a good idea to return the volume to its last setting.

This is a small example. Which gets the current volume level, gets the duration of the file
(best use a short file, I have a short feed back loop) plays the file over the output sound and delays
(pauses before any more commands in the script) for the duration of the sound file, and then returns the volume back to its original level.

You can add to it a check to see if certain apps like iTunes is running (look at application processes running), which will not open iTunes if it is not open already.
But I do not have time to day to add that. It simple and there should be lots of examples out there. The example:

property mySound : "/Users/USERNAME/Music/Other/shortFeedBackLoopmp3" -- Path to sound file 

on run
	-- get current  sound volume
	set av to output volume of (get volume settings)
	set volume output volume 100
	-- go to play  sound file
	set_system_sound() -- set new sound
	--return to original sound
	set volume output volume av
end run

on set_system_sound()
	-- get the duration of the sound file
	set timer to last word of (do shell script "mdls -name kMDItemDurationSeconds " & quoted form of mySound) as number
	-- go to play  sound file
	do shell script "afplay " & quoted form of mySound & " > /dev/null 2>&1 &"
	delay timer
end set_system_sound 

[ Reply to This | # ]