quicksilver/creations/applescript_attenuate.txt · Last modified: 2010/07/14 03:19 (external edit)


Here's a script I wrote in reference to this topic in the forum. The original is zipped up here: http://www.digidiesel.com/people/ed/iTunesAttenuate.zip . Feel free to edit or steal this code. You don't even need to give me credit.

-- iTunes Attenuate button
-- E. Palma 11/10/2005
-- ed@digidiesel.com
-- Free.

-- Purpose: This script "Attenuates" or quiets iTunes while leaving it playing; 
-- After all who wants to stop the tunes to answer the phone?  Running the script
-- again returns the volume to the previous level (before Attenuation).

-- This script creates the file ~/Library/Preferences/QS_iTunesState which stores
-- the pre-Attenuated volume

--User Settings: How quiet do you want it (enter 0 to 100)
set attLevel to 5


-- You don't need to edit bellow this line unless you want to add/change features
-- fading-in might be nice- but I'm studying for a Microbiology midterm at the moment
try
	set previousVolume to (read alias (((path to preferences folder) as text) & "QS_iTunesState"))
on error
	set this_file to (((path to preferences folder) as text) & "QS_iTunesState")
	my write_to_file("5", this_file, false)
	set previousVolume to 5
end try
tell application "iTunes"
	set currentVolume to sound volume as string
end tell

if currentVolume is equal to (attLevel as text) then
	tell application "iTunes"
		set sound volume to previousVolume
	end tell
else
	tell application "iTunes"
		set this_file to (((path to preferences folder) as text) & "QS_iTunesState")
		my write_to_file(currentVolume, this_file, false)
		set sound volume to attLevel
	end tell
end if

--This is just an Apple file routine demo
on write_to_file(this_data, target_file, append_data)
	try
		set the target_file to the target_file as text
		set the open_target_file to ¬
			open for access file target_file with write permission
		if append_data is false then ¬
			set eof of the open_target_file to 0
		write this_data to the open_target_file starting at eof
		close access the open_target_file
		return true
	on error
		try
			close access file target_file
		end try
		return false
	end try
end write_to_file