Need help with remote script

EP922
New Contributor

I need some help writing a script to push out to student machines. We are trying to disable Expose/Mission Control/Spaces. I know there are a few other threads on this topic using config profiles, but I was looking for a script to push out as well with Casper Remote to add to our arsenal. I can go to a student machine, open terminal and run these commands:

defaults write com.apple.dock mcx-expose-disabled -bool TRUE
defaults write com.apple.dashboard mcx-disabled -boolean YES
killall Dock

Doing so disables what we need disabled. I tried to turn it into a script for Casper Remote as follows:

#!/bin/sh
defaults write com.apple.dock mcx-expose-disabled -bool TRUE
defaults write com.apple.dashboard mcx-disabled -boolean YES
killall Dock

Remotely pushing this out does not work though. I also tried adding a sudo to the first line with no luck. I'm guessing this needs to be pushed out at the user level. We use a couple of different generic accounts. I'm not sure how to write the script for each account. I may be going about this the wrong way. Any help or suggestions would be appreciated!

1 ACCEPTED SOLUTION

chriscollins
Valued Contributor

There are a ton of posts on here on how to do this but here you go ;)

#!/bin/sh

useris=$(ls -l /dev/console | awk -F"1 " '{print $2}' | awk -F"  " '{print $1}')

sudo -u "$useris" defaults write com.apple.dock mcx-expose-disabled -bool TRUE
sudo -u "$useris" defaults write com.apple.dashboard mcx-disabled -boolean YES
killall Dock

View solution in original post

7 REPLIES 7

chriscollins
Valued Contributor

There are a ton of posts on here on how to do this but here you go ;)

#!/bin/sh

useris=$(ls -l /dev/console | awk -F"1 " '{print $2}' | awk -F"  " '{print $1}')

sudo -u "$useris" defaults write com.apple.dock mcx-expose-disabled -bool TRUE
sudo -u "$useris" defaults write com.apple.dashboard mcx-disabled -boolean YES
killall Dock

mm2270
Legendary Contributor III

Its almost kind of funny, and sad at the same time, how this topic of "how do I get X to run as the logged in user when doing it out of Casper?" comes up just about every other day on a post here.

This, to me, makes a good case for this Feature Request (which is sadly labeled as Not Planned) It would be nice if JAMF could oblige with something like this though, maybe done in their own style.
I think no-one really minds questions being asked since that's what the forum is about, but topics like these would be awesome to have in a "Common topics" list, or a "Top questions asked" kind of section that new (or old) forum users could go right to. Otherwise these very important topics just get buried on another page in a matter of hours and aren't easily seen unless you know exactly what to search for.

chriscollins
Valued Contributor

@mm2270 Totally agreed. At the least they could make it a knowledge base article with a recommended way of doing it that we could just point people to easily with a clear and concise explanation. The only reason I don't usually drop a link to a thread is I feel bad for leaving someone to dig through a bunch of posts in a thread for the right answer. Well, that and I don't really feel like having to do a search for a thread myself with the best concise explanation just to point somebody else to it, since that feels like doing the work for them anyway. Its faster to help them on the thread they posted.

EP922
New Contributor

Thank you for the help!

Schmidty
New Contributor III

What would be the trick to getting this to work in self service or pushed out at login? I can get it to work in a shell script on a computer but when I put it into self service it doesn't seem to work.

Thanks

EP922
New Contributor

You can try taking the script in the post from chriscollins, add it to Casper Admin, then create a policy where it runs that script on startup. I haven't tried this personally. I've been using Casper Remote to push it out when needed.

agetz
Contributor

Old post but confirmed chriscollins's script runs fine from self service as well as through a trigger on our 10.11 machines.