How to listen for Line-out input?

Hey, I’m new to this forum, but am fairly decent with applescript and some other languages too. I use my macbook to play my iTunes all the time, often swapping between my 2.1 speakers, headphones, and internal speakers, and I use 3 different Equalizer settings. I created a small script I keep on my dock next to itunes, that lets me switch my equalizer with 1 click, but that isn’t good enough for me! I want to be able to have an always open script, that on idle will check the Line out port, and when the state changes, display my dialog box with my EQ choices, but I have no clue on where to find that at all… any ideas? The script as it is can be found at http://eovnu87435ds.pastebay.org/9834

Model: Macbook 13" Unibody
AppleScript: 2.0.1
Browser: Safari 528.16
Operating System: Mac OS X (10.5)

This script might help you get there; I use it for switching between sources, but you can modify it to do what you want. BTW, your script link doesn’t reveal your script.

tell application "System Preferences" to reveal anchor "output" of pane id "com.apple.preference.sound"
tell application "System Events" to tell (table 1 of scroll area 1 of tab group 1 of window "Sound" of application process "System Preferences")
	set S to selected of rows
	if item 1 of S is false then
		select row 1
		set msg to "External Speakers"
	else
		select row 3
		set msg to "Earphones" -- in my case, USB Earphones.
	end if
end tell
-- more stuff to display a message here.

Thanks for the quick reply! I also modified the link so it is directly to the code. after taking a quick look as your code, it seems the easiest method is to have on run, check what the output is, then save it to a variable. then on idle keep checking. when it isnt the same, open the dialog, let me choose my EQ, then set the variable to the new current output.

Thanks!

whoops… that wont work! Since both the line out jack and internal speakers the same output device, I cant distinguish between the 2 unless there is a way to read the name of the option. does anybody know where the plist file is for this? mabye it can be read out of there

EDIT: This plist changes depending on what output is chosen, but I do not see any difference in it when the name changes from headphones to internal speakers. (/Library/Preferences/com.apple.audio.SystemSettings.plist)

Oops; I missed that you were sometimes using the internal speakers. Here’s a revised version:


tell application "System Preferences" to reveal anchor "output" of pane id "com.apple.preference.sound"
tell application "System Events" to tell (table 1 of scroll area 1 of tab group 1 of window "Sound" of application process "System Preferences")
	set S to selected of rows
	if item 1 of S then -- first row is selected
		set T to value of text field 1 of row 1 -- this will be either "Line Out" or "Headphones", I think, and you can act on that.
	else if item 2 of S then -- second row is selected
		set T to value of text field 1 of row 2
	end if
end tell

Thanks for your script too.

Wow, i feel stupid now! I kept trying name but couldn’t think of value! it works! thanks!