Posted on 04-29-2015 09:50 AM
I'm trying to figure out a way to disable iTunes from launching when pressing the F8 play/pause button. We have hundreds of computers in our school district doing Smarter Balanced testing. The students are figuring out that pressing F8 will launch iTunes and crash the test. I'm looking for a way to get a working script to use with Casper Remote and to set up policies with.
This command works one-to-one:
launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist
So I tried to make it into:
#!/bin/bash
launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist
But this does not prevent iTunes from launching with F8 when pushing out as a script through Casper Remote. I have also tried to just execute as a command (without #!/bin/bash) with Casper Remote with no luck.
For a temporary solution I have removed iTunes from the machines before we reimage this summer with this script:
#!/bin/bash
rm -rf /Applications/iTunes.app/
We would prefer to not completely remove iTunes from the machines, we just want to disable the keyboard shortcut. We are aware you can set the keyboard preference to force the Fn key to be pressed to use the special features for the F keys. Again, this is not feasible as the students will figure that out as well.
Any suggestions on a workable script or a package that runs the script to disable launching iTunes with F8 that can be pushed out with Remote and policies?
Thanks!
Solved! Go to Solution.
Posted on 04-29-2015 01:23 PM
I currently use restrictions to block itunes on testing machines. I make sure it shows no message and then it just opens and closes.
Nice and easy!
Gabe Shackney
Princeton Public Schools
Posted on 04-29-2015 02:56 PM
The issue is that, although that LaunchAgent lives inside the System directory, its actually a user level agent, so when it runs from Casper, its running as root, i.e, with sudo, which doesn't work for that Agent. I just tried it manually with sudo launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist and got an error, but it worked fine to disable it when I dropped the sudo from the command.
Try doing it this way, which gets the logged in user's PID and then uses launchctl bsexec to run the command as the user, not as root.
#!/bin/sh
declare -x loggedInUser="$(ls -l /dev/console | /usr/bin/awk '{print $3;exit}')"
declare -x LoginWindowPID="$(/bin/ps -axww | /usr/bin/grep loginwindo[w] | /usr/bin/awk '/console/{print $1;exit}')"
/bin/launchctl bsexec "${LoginWindowPID:?}" /usr/bin/sudo -u "$loggedInUser" /bin/launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist
Try that and see if it works. Of course, this assumes a user is logged in or it probably won't work. It could be fleshed out to check if the "loggedInUser" variable comes back as "root" or something else first.
Posted on 04-29-2015 01:23 PM
I currently use restrictions to block itunes on testing machines. I make sure it shows no message and then it just opens and closes.
Nice and easy!
Gabe Shackney
Princeton Public Schools
Posted on 04-29-2015 02:29 PM
So iTunes will open and close quickly using this method? That is part of the problem - iTunes opening at all will crash this testing software. It's a good approach if it weren't for that aspect.
Posted on 04-29-2015 02:37 PM
I thought the same thing however it's so quick that it didn't affect the PARCC test software which also shuts down if anything else is detected.
I'd say test it out to see if it works for that software as well.
Posted on 04-29-2015 02:52 PM
Looks like I spoke too soon. This solution worked. Thanks, gshackney!
Posted on 04-29-2015 02:56 PM
The issue is that, although that LaunchAgent lives inside the System directory, its actually a user level agent, so when it runs from Casper, its running as root, i.e, with sudo, which doesn't work for that Agent. I just tried it manually with sudo launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist and got an error, but it worked fine to disable it when I dropped the sudo from the command.
Try doing it this way, which gets the logged in user's PID and then uses launchctl bsexec to run the command as the user, not as root.
#!/bin/sh
declare -x loggedInUser="$(ls -l /dev/console | /usr/bin/awk '{print $3;exit}')"
declare -x LoginWindowPID="$(/bin/ps -axww | /usr/bin/grep loginwindo[w] | /usr/bin/awk '/console/{print $1;exit}')"
/bin/launchctl bsexec "${LoginWindowPID:?}" /usr/bin/sudo -u "$loggedInUser" /bin/launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist
Try that and see if it works. Of course, this assumes a user is logged in or it probably won't work. It could be fleshed out to check if the "loggedInUser" variable comes back as "root" or something else first.
Posted on 04-30-2015 07:42 AM
Thanks, mm2270! This script also works as a solution to the problem we are having. Thanks everyone, we really appreciate it!