Posted on 11-11-2014 02:45 PM
I could find any other info about this, so I figured I'd post this script that I created for disabling Handoff without using the GUI. There are two settings that need to change, and they are located inside a plist file in: ~/Library/Preferences/ByHost
We use this in conjunction with a launchdaemon to make sure that this stays disabled for our users.
#!/bin/bash
loggedInUser=$(ls -l /dev/console | awk '{ print $3 }')
uuid=$(/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57)
handoff1=$(defaults read /Users/$loggedInUser/Library/Preferences/ByHost/com.apple.coreservices.lsuseractivityd.$uuid.plist ActivityAdvertisingAllowed)
handoff2=$(defaults read /Users/$loggedInUser/Library/Preferences/ByHost/com.apple.coreservices.lsuseractivityd.$uuid.plist ActivityReceivingAllowed)
echo "$handoff1"
echo "$handoff2"
if [[ "$handoff1" == "0" || "$handoff2" == 0 ]]; then
echo "Exit Message: OK"
exit 0
else
defaults write /Users/$loggedInUser/Library/Preferences/ByHost/com.apple.coreservices.lsuseractivityd.$uuid.plist ActivityAdvertisingAllowed -bool no
defaults write /Users/$loggedInUser/Library/Preferences/ByHost/com.apple.coreservices.lsuseractivityd.$uuid.plist ActivityReceivingAllowed -bool no
echo "Exit Message: Handoff Disabled"
fi
exit 1
Posted on 11-14-2014 01:37 PM
Thanks for sharing. I haven't thought this through completely but I'm curious, why would you want to disable Handoff? I take it there's something it does that creates a problem. But what is that problem? Again, I haven't given this much thought but figured I'd ask to get your perspective.
Posted on 11-19-2014 01:22 PM
Our Security team was concerned that customer data could easily pop up on non-company-owned computers/devices. We don't prevent our users from enabling iCloud, so the thought was that an email or a document that was in the process of being composed on a work computer could inadvertently get copied to a user's personal Mac or iOS device. Rather than educate our users not to do this, we created a launchdaemon to turn Handoff off on OS X.
Posted on 11-19-2014 06:18 PM
While your concerns are valid, there may not be a need to worry.
As handoff relies on both (or multiple) devices being signed in with the same iCloud account AND being in 30 ft proximity of each other with bluetooth enabled (also must support BT LE) AND need to be on the same network/subnet, pretty sure unless all this is met, handoff will not work.
Also documents/mail will not handoff to another device unless the end user interacts with the receiving device to tell it to pick up the document/mail via handoff.
- Sean
Posted on 04-02-2015 09:06 AM
@bmarks - How is this working for you? Well? The launchdaemon you used, how often do you have it set to run for it to be effective? Any help would be appreciated.
Posted on 01-08-2016 06:32 AM
Does this script work on Yosemite? Has anyone tried an Automator App?
Posted on 02-08-2016 07:42 AM
This script seems to be working with some modifications in El Capitan. Our problem is that the first pass through produces a file not found error. Then if handoff is enabled it won't always reliably disable. Not sure what the reason for that is. We set the option to be && and not ||. How is it working in your environment?
Posted on 02-08-2016 10:17 AM
(EDIT: Actually, the below info may have always been the case. With that said, I had no issues running it as-is on El Capitan.)
I wonder if you need to run it with elevated privileges since there's a command in the script that's now in a SIP-protected directory. I got the following output just now without sudo'ing first:
2016-02-08 10:12:52.901 defaults[9771:4745243]
The domain/default pair of (/Users/bmarks/Library/Preferences/ByHost/com.apple.coreservices.lsuseractivityd.A66713F0-EF1E-5CFA-8E9C-60755DFCE01B.plist, ActivityAdvertisingAllowed) does not exist
2016-02-08 10:12:52.960 defaults[9772:4745267]
The domain/default pair of (/Users/bmarks/Library/Preferences/ByHost/com.apple.coreservices.lsuseractivityd.A66713F0-EF1E-5CFA-8E9C-60755DFCE01B.plist, ActivityReceivingAllowed) does not exist
However, I get the expected results if I elevate to root privileges.
Posted on 02-17-2016 08:25 AM
We experienced the exact same issues and elevating privileges helped as well. Thanks for the info, works in El Capitan for sure.
Posted on 03-17-2016 03:45 PM
This script runs sucessfully for me with elevated privileges on El Capitan (10.11.3). However, when I go to System Preferences > General, Handoff is still enabled. Anyone else notice that?
Also, has anyone tried adapting this as an MDM profile and had success?
Posted on 09-02-2016 06:57 AM
How are you running this as a policy? I tried to trigger at login, but absolutely nothing happens...
Posted on 09-02-2016 07:46 AM
I modified the script a bit to hit up all users on the local machine and to change things only when they need it. A big thing was the script was set to turn off only if turned on (if missing, fail miserably).
#!/bin/bash
LocalHomes=$(/usr/bin/dscl . -list /Users NFSHomeDirectory | grep -v /var/ | grep -v /Library/ | awk '$2 ~ /^// {print $2;}')
uuid=$(/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57)
for OneHome in $LocalHomes; do
handoff1=$(defaults read $OneHome/Library/Preferences/ByHost/com.apple.coreservices.lsuseractivityd.$uuid.plist ActivityAdvertisingAllowed)
handoff2=$(defaults read $OneHome/Library/Preferences/ByHost/com.apple.coreservices.lsuseractivityd.$uuid.plist ActivityReceivingAllowed)
if [[ "$handoff1" != "0" ]]; then
defaults write $OneHome/Library/Preferences/ByHost/com.apple.coreservices.lsuseractivityd.$uuid.plist ActivityAdvertisingAllowed -bool no
fi
if [ "$handoff2" != "0" ]; then
defaults write $OneHome/Library/Preferences/ByHost/com.apple.coreservices.lsuseractivityd.$uuid.plist ActivityReceivingAllowed -bool no
fi
done
Posted on 11-27-2016 10:21 PM
this script doesn't work for me neither on 10.11 nor 10.12
any ideas?
i've got the same output of it doesn't exsit.
Posted on 02-21-2017 11:48 AM
I modified the above script to allow for two policies; one to disable and another to enable handoff on macOS Sierra devices (to facilitate high stakes testing).
Disable Handoff for all users:
#!/bin/bash
LocalHomes=$(/usr/bin/dscl . -list /Users NFSHomeDirectory | grep -v /var/ | grep -v /Library/ | awk '$2 ~ /^// {print $2;}')
for OneHome in $LocalHomes; do
userName=$(/bin/echo $OneHome | awk -F "/" '{print $NF;}')
sudo -u $userName defaults write $OneHome/Library/Preferences/ByHost/com.apple.coreservices.useractivityd.plist ActivityAdvertisingAllowed -bool no
sudo -u $userName defaults write $OneHome/Library/Preferences/ByHost/com.apple.coreservices.useractivityd.plist ActivityReceivingAllowed -bool no
done
Enable Handoff for all users:
#!/bin/bash
LocalHomes=$(/usr/bin/dscl . -list /Users NFSHomeDirectory | grep -v /var/ | grep -v /Library/ | awk '$2 ~ /^// {print $2;}')
for OneHome in $LocalHomes; do
userName=$(/bin/echo $OneHome | awk -F "/" '{print $NF;}')
sudo -u $userName defaults write $OneHome/Library/Preferences/ByHost/com.apple.coreservices.useractivityd.plist ActivityAdvertisingAllowed -bool yes
sudo -u $userName defaults write $OneHome/Library/Preferences/ByHost/com.apple.coreservices.useractivityd.plist ActivityReceivingAllowed -bool yes
done
Posted on 06-07-2017 05:21 AM
Just tried the 'Disable Handoff' script on Sierra 10.12.5 and it doesn't seem to do anything.
'System Preferences', 'General' - still showing the tick within 'Allow Handoff between this Mac and your iCloud devices'
Posted on 06-12-2017 04:40 AM
Oops! the script does work, just needs user to logoff/restart to take effect.
Does anyone know of a way to actually disable this options via configuration profile, so the user can't switch it on again themselves?
Thanks in advance
Posted on 05-24-2018 12:57 PM
jcarr's scripts work here. Thanks!
Posted on 09-01-2021 05:20 AM
Hi Everyone I used the script and also did a restart this didn't work. Any ideas, please?
09-01-2021 08:37 AM - edited 09-01-2021 08:38 AM
Use a Configuration Profile.
Restrictions Payload
Under the tab Functionality
uncheck Allow Handoff (macOS 10.15 or later)
Posted on 09-07-2021 02:06 AM
Hi @burdett - thank you for your replay I have this already in place and it seems this doesn't work, I have applied the scope to my MAC to see if this works and it still showing as ticketed on, and then I used the scripts provided above and still not working. Any other ideas would be really helpful? Thank you.
Posted on 09-07-2021 03:49 AM
I have a way of using the terminal to do this -
sudo -u $(whoami) defaults write "$HOME/Library/Preferences/ByHost/com.apple.coreservices.useractivityd.plist" ActivityAdvertisingAllowed -bool no
this seems to work now I need to find a way to imbed this in JAMF so we do not need to do this manually.
Posted on 09-07-2021 10:35 AM
@Habib-Rahman, sorry I over looked were your were using macOS Sierra 10.12.5, Configuration profiles need macOS 10.15 or later.
For this system create a policy in jamf, choose options -> Files and Processes, add your command in the field "Execute Command". Choose options -> General, -> Execution Frequency, set to run once per user per computer. In the scope add your device. This should Disable Handoff.
Posted on 09-07-2021 12:01 PM
Hi @burdett thank you for the advice I did what you said and done many restarts however this still not working.
It still shows as enabled however when I run this command manually i works:
sudo -u $(whoami) defaults write "$HOME/Library/Preferences/ByHost/com.apple.coreservices.useractivityd.plist" ActivityAdvertisingAllowed -bool no
I even have a Configuration Profiles >> Restrictions >> Functionality >>Allow Handoff (macOS 10.15 or later)
Even though I have turned it off, nothing seems like it's working? any ideas what else I can do please?
Thank you so much.
Habib
09-13-2021 08:21 AM - edited 09-13-2021 08:23 AM
Habib-Rahman, When JAMF runs a command it runs it as an elevated account using the JAMF manager account. I don't think
sudo -u $(whoami)
is returning the correct value. For these older macOS < 10.15 I would create and test the script thoule posted on 09-02-2016. This scrip is using a different method for setting the path for the users home folder. For devices running current macOS > 10.52, Use a Configuration Profile with Restrictions Payload and uncheck uncheck Allow Handoff.
Posted on 09-14-2021 01:35 AM
Hi @burdett - thank you for your reply I have macOS > 10.52, Use a Configuration Profile with Restrictions Payload and uncheck Allow Handoff, however it seems still not to be working as well, I have tested multiple times with different variants however for some this doesn’t seem to work.
When you run this command on terminal it works defaults -currentHost write com.apple.coreservices.useractivityd ActivityAdvertisingAllowed -bool no
But when I do the Configuration Profiles >> Restrictions >> Functionality >>Allow Handoff (macOS 10.15 or later) nothing seems to happen.