Please Help, I cannot figure out what I am doing wrong!

Please help me, I am not sure what I am doing wrong…

I currently have my MacBook setup so that I can watch my movies on my television. But my work laptop died, so now I am forced to use my MacBook for all of my computing needs.

I am wanting to write an applescript that allows my at system startup to say whether or not I want to use my MacBook as a TV Media Device or as a work station.

To do this I wanted to have a dialog box open on startup so I can make the decision.

If I use the Television, I wanted to have:

  1. the MacBook screen go completely dark, since the television is the viewing area
  2. open iTunes, so I can have it update any podcasts/shows/ect… then have iTunes hide in the background
  3. open an application called Hear, so I can have a decent sound system for watching movies
  4. Hide the Hear application
  5. launch Front Row

If I choose to Use the Computer, I wanted to have:

  1. the screen at full brightness, since the computer will not be connected to my television
  2. volume at full

I just cannot figure out what I am doing wrong. I think maybe I need another “end tell” but I am just not sure.

Any help would be greatly appreciated.

Regards,
paulmattallen


set question to display dialog "What would you like to do?" buttons {"Watch TV", "Use Computer"} default button 2 with icon caution giving up after 20
set answer to button returned of question

if answer is equal to "Watch TV" then
	tell application "iTunes"
		activate
		delay 5
	tell application "System Events"
		set visible of process "iTunes" to false
	end tell
	tell application "System Preferences"
		activate
		set current pane to pane "com.apple.preference.displays"
	end tell
	
	tell application "System Events" to tell process "System Preferences"
		tell slider 1 of group 2 of tab group 1 of window 1 to set value to 0
	end tell
	
	tell application "System Preferences"
		quit "System Preferences"
	end tell
	
	delay 2
	
	set volume 7
	
	delay 5
	tell application "Hear"
		activate
	end tell

if answer is equal to "Use Computer" then
	tell application "System Preferences"
		activate
		set current pane to pane "com.apple.preference.displays"
	end tell
	
	tell application "System Events" to tell process "System Preferences"
		tell slider 1 of group 2 of tab group 1 of window 1 to set value to 10
	end tell
	
	tell application "System Preferences"
		quit "System Preferences"
	end tell
	
	delay 2
	
	set volume 7
end tell

This is the correct structure. I haven’t checked it to see if the script actually works.


set question to display dialog "What would you like to do?" buttons {"Watch TV", "Use Computer"} default button 2 with icon caution giving up after 20
set answer to button returned of question

if answer is equal to "Watch TV" then
	tell application "iTunes"
		activate
	end tell
	delay 5
	tell application "System Events"
		set visible of process "iTunes" to false
	end tell
	tell application "System Preferences"
		activate
		set current pane to pane "com.apple.preference.displays"
	end tell
	
	tell application "System Events" to tell process "System Preferences"
		tell slider 1 of group 2 of tab group 1 of window 1 to set value to 0
	end tell
	
	tell application "System Preferences"
		quit "System Preferences"
	end tell
	
	delay 2
	
	set volume 7
	
	delay 5
	tell application "Hear"
		activate
	end tell
	
else if answer is equal to "Use Computer" then
	tell application "System Preferences"
		activate
		set current pane to pane "com.apple.preference.displays"
	end tell
	
	tell application "System Events" to tell process "System Preferences"
		tell slider 1 of group 2 of tab group 1 of window 1 to set value to 10
	end tell
	
	tell application "System Preferences"
		quit "System Preferences"
	end tell
	
	delay 2
	
	set volume 7
end if