script to Toggle Apple Remote Control Enable/Disable

In System Preferences > Security > General, at the bottom s check box to disable remote control infrared receiver. I’d like to develop a widget that when clicked on will toggle whether or not the Apple Remote infrared receiver is enabled or disabled.

I Googled the topic and came across this script:

set currentValue to do shell script "defaults read /Library/Preferences/com.apple.driver.AppleIRController DeviceEnabled"
if currentValue is "0" then
	set status to "disabled"
else
	set status to "enabled"
end if


display dialog "Set remote control infrared. Right now it is " & status & "." buttons {"Enable", "Disable", "Cancel"} default button "Disable"
copy button returned of the result to button
if button = "Cancel" then
	return
end if

-- only change it if it needs to be changed

-- currently disabled and button is enable
if currentValue is "0" and button is "Enable" then
	do shell script "defaults write /Library/Preferences/com.apple.driver.AppleIRController DeviceEnabled -bool yes" with administrator privileges
	return
end if
-- currently enabled and button is disable
if currentValue is "1" and button is "Disable" then
	do shell script "defaults write /Library/Preferences/com.apple.driver.AppleIRController DeviceEnabled -bool no" with administrator privileges
	return
end if

The script runs and checks/unchecks the box, but doesn’t actually enable/disable the remote control infrared receiver (tested it with iTunes). Can anyone tell me why this script doesn’t work? Also, is it possible to not have to enter your password? As I mentioned, I’m planning to make it into a widget that will run the script.

Thanks - slimjim5811

Hi,

I guess that during the write operation into the main Library you are changing the access privileges.
Most of the pref files in /Library are owned by root (r/w) with group wheel (r/o)

For security reasons you can’t perform a root or admin operation without the admin password.
I hope Apple will never change this!!
Either you type it in or you include it in the shell script line.

Edit: A smaller version of your script :wink:


try
	set currentValue to (((do shell script "defaults read /Library/Preferences/com.apple.driver.AppleIRController DeviceEnabled") as integer) + 1)
	set status to item currentValue of {"disabled", "enabled"}
	set button to (display dialog "Set remote control infrared. Right now it is " & status & "." buttons {"Cancel", item currentValue of {"Enable", "Disable"}} default button 2)
	do shell script "defaults write /Library/Preferences/com.apple.driver.AppleIRController DeviceEnabled -bool " & item currentValue of {"yes", "no"} with administrator privileges
end try

Thanks Stefan -
But does it actually work for you? I can still use the remote after disabling it.

I don’t have any Apple Remote.

PS: I have not considered the access privileges issue in my version of the script.
Normally if you write into /Library with user defaults, the owner is set to yourself, and then unexpected things can happen.
Check it with a new created plist file by the system.