pattulus
9/15/2014 - 8:48 PM

Podcasting Scripts

Podcasting Scripts

on run
	
	# Disable Notification Center
	tell application "System Events"
		option key down
		delay 0.2
		try
			click menu bar item "NotificationCenter, Do Not Disturb enabled" of menu bar 2 of application process "SystemUIServer"
		end try
		option key up
	end tell
	
	# Launch Dropbox
	tell application "Dropbox" to launch
	
	#Turn of Caffeine
	tell application "Caffeine" to quit
	
	# Turn on Function Keys
	set FunctionKey to "defaults read \"Apple Global Domain\" com.apple.keyboard.fnState"
	set FunctionKeyStatus to do shell script FunctionKey
	
	repeat 3 times
		set FunctionKeyStatus to do shell script FunctionKey
		tell application "System Preferences"
			reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
		end tell
		tell application "System Events" to tell process "System Preferences"
			click checkbox 1 of tab group 1 of window 1
		end tell
		quit application "System Preferences"
		
		if FunctionKeyStatus = "1" then exit repeat
	end repeat
	if FunctionKeyStatus = "1" then
		do shell script "/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -title '✅ Okay!' -message 'Everything is back to normal!' -sender com.manytricks.KeyCodes"
	else if FunctionKeyStatus = "0" then
		do shell script "/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -title '⚠️ Failure!' -message 'Function Keys still active!' -sender com.peterborgapps.LingonX2"
		--error number -128
	end if
	
	# Stop Recording Session	
	tell application "Audio Hijack Pro"
		activate
		
		# Variables for session names
		set trackMic to the first session whose name is "☲ MIC ☲" -- routed IN 2 to CH. 3 via TotalMix Loopback
		set trackSkype to the first session whose name is "☲ Skype ☲" -- on default CH 1/2
		set trackFX to the first session whose name is "☲ FX ☲" -- routed IN 5/6 to CH. 1/2 via TotalMix Loopback
		
		# Start Hijacking
		stop hijacking trackMic
		--stop hijacking trackSkype
		stop hijacking trackFX
		
	end tell
	
end run
on run
	
	# Disable Notification Center	
	#do shell script "launchctl load /System/Library/LaunchAgents/com.apple.notificationcenterui.plist" # Depracted in Yosemite
	tell application "System Events"
		option key down
		delay 0.2
		try
			click menu bar item "Notification Center" of menu bar 2 of application process "SystemUIServer"
		end try
		option key up
	end tell
	
	# Quit Dropbox
	tell application "Dropbox" to quit
	
	# Quit Tweetbot
	tell application "Tweetbot" to quit
	
	# Turn off Caffeine
	tell application "Caffeine"
		if not active then
			turn on
		end if
	end tell
	
	# Turn off Function Keys (to avoid messing with the Skype level)
	set FunctionKey to "defaults read \"Apple Global Domain\" com.apple.keyboard.fnState"
	set FunctionKeyStatus to do shell script FunctionKey
	
	repeat 3 times
		--display dialog "Please enter your name:" default answer ""
		--set FunctionKeyStatus to text returned of result
		set FunctionKeyStatus to do shell script FunctionKey
		tell application "System Preferences"
			reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
		end tell
		tell application "System Events" to tell process "System Preferences"
			click checkbox 1 of tab group 1 of window 1
		end tell
		quit application "System Preferences"
		
		if FunctionKeyStatus = "0" then exit repeat
	end repeat
	if FunctionKeyStatus = "1" then
		do shell script "/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -title '⚠️ Failure!' -message 'Disabling Function Keys did`t work!' -sender com.peterborgapps.LingonX2"
	else if FunctionKeyStatus = "0" then
		do shell script "/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -title ' Ready to Podcast!' -message 'Function Keys disabled!' -sender com.rogueamoeba.AudioHijackPro2 -activate com.rogueamoeba.AudioHijackPro2"
		--error number -128
	end if
	
	# Start Recording Session
	tell application "Audio Hijack Pro"
		launch
		activate
		
		# Variables for session names
		set trackMic to the first session whose name is "☲ MIC ☲" -- routed IN 2 to CH. 3 via TotalMix Loopback
		set trackSkype to the first session whose name is "☲ Skype ☲" -- on default CH 1/2
		set trackFX to the first session whose name is "☲ FX ☲" -- routed IN 5/6 to CH. 1/2 via TotalMix Loopback
		
		# Start Hijacking
		start hijacking trackMic
		start hijacking trackSkype
		start hijacking trackFX
		delay 3
		
		# Start Recording
		start recording trackMic
		start recording trackSkype
		start recording trackFX
		
		-- tell trackMic to start recording
		-- tell trackSkype to start recording
		
	end tell
	
end run