3

Is there a way to enable/disable the Handoff setting from the command line?

Currently, I'm using macOS Mojave 10.14.3 and I know I can toggle it by going to Settings > General > "Allow Handoff" - but looking for an alternate way.

Handoff toggle in settings

3
  • 1
    There is a scritpt here, but it does not seem to work under 10.14: jamf.com/jamf-nation/discussions/12545/…
    – slhck
    Commented Apr 1, 2019 at 20:20
  • It works! I need to test it more, but you @slhck should get the answer points for this one! The supplied full bash scripts didn't work out-of-the-box, but the raw commands to update the useractivityd.plist work from this post: jamf.com/jamf-nation/discussions/12545/… -- Didn't even have to log on/off to see the preference updated.
    – brandonjp
    Commented Apr 11, 2019 at 1:07
  • Good to know. Yeah, these bash scripts are not coded well.
    – slhck
    Commented Apr 11, 2019 at 6:53

2 Answers 2

6

The following commands should turn Handoff off:

sudo -u $(whoami) defaults write "$HOME/Library/Preferences/ByHost/com.apple.coreservices.useractivityd.plist" ActivityAdvertisingAllowed -bool no
sudo -u $(whoami) defaults write "$HOME/Library/Preferences/ByHost/com.apple.coreservices.useractivityd.plist" ActivityReceivingAllowed -bool no

To turn on again:

sudo -u $(whoami) defaults write "$HOME/Library/Preferences/ByHost/com.apple.coreservices.useractivityd.plist" ActivityAdvertisingAllowed -bool yes
sudo -u $(whoami) defaults write "$HOME/Library/Preferences/ByHost/com.apple.coreservices.useractivityd.plist" ActivityReceivingAllowed -bool yes

Source: jamf.com – note that I have not verified the commands, but the OP claims them to be working.

2
  • Using these every day on macOS Mojave 10.14.3. Thanks again!
    – brandonjp
    Commented Apr 16, 2019 at 3:48
  • "$HOME/Library/Preferences/ByHost/com.apple.coreservices.useractivityd.plist" does not exist on my fresh Mojave install, 10.14.5 Commented Jun 23, 2019 at 3:35
5

@slhck's answer can be simplified to:

On:

defaults -currentHost write com.apple.coreservices.useractivityd ActivityAdvertisingAllowed -bool yes
defaults -currentHost write com.apple.coreservices.useractivityd ActivityReceivingAllowed -bool yes

Off:

defaults -currentHost write com.apple.coreservices.useractivityd ActivityAdvertisingAllowed -bool no
defaults -currentHost write com.apple.coreservices.useractivityd ActivityReceivingAllowed -bool no

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .