• Mac OS X,  Mac OS X Server,  Mac Security,  Mass Deployment

    Scripting Volume Control in OS X

    I’ve always found the easiest way to script the volume of an OS X computer (and when I say volume I mean sound level, not a logical volume created from partitioning a hard drive – but I have articles for scripting those as well) is using the osascript command to invoke an Applescript command that sets the volume to zero. To put some syntax around this: osascript -e "set volume 0"

  • Mac OS X,  Mac OS X Server,  Mac Security,  Mass Deployment

    Find or Kill A Signal By Name In OS X

    You can query whether a process is running by name. You can do this with ps and pipe the output to grep. It’s not hard, but you can do this more quickly with pgrep. You can also kill that process with pkill. Which includes the ability to send a signal. So, let’s look at closing down iTunes with pkill: pkill iTunes Or we can send it with a signal (9): pkill -9 iTunes Or you could just grab the pid of a process by name: pgrep Safari It might display: 797 And that’s it. Easy Peasy.

  • Mac OS X,  Mac OS X Server,  Mac Security,  Mass Deployment

    Hide Safari’s Bookmarks Bar

    Safari has a bookmarks bar. Some people want to hide it. A lot of people used to do stuff like this by modifying the default user template in OS X. Not something we’ll be doing much in the future. So to do so with a script: defaults write com.apple.Safari ShowFavoritesBar -bool false To turn it back on: defaults write com.apple.Safari ShowFavoritesBar -bool true

  • Mac OS X,  Mac OS X Server,  Mac Security,  Ubuntu,  Unix

    Using Inputs in Bash Scripts

    You can easily accept user provided input in bash by using the read command in bash for Linux and OS X. Here, we’ll echo out a choice to a user in a script, read the output into a variable called yn and then echo out the response: echo "Please enter y or n: " read yn echo "You chose wrong: $yn" Here, we used echo to simply write out what was chosen in the input. But we could also take this a little further and leverage a case statement to then run an action based on the choice selected: read -p "Should the file extension change warning be disabled (y/n)?…

  • Mac OS X,  Mac OS X Server,  Mac Security,  Ubuntu,  Unix

    Grab Your WAN IP In Scripts

    Sometimes when I’m writing a script, I need something to phone home to something in the script. For example, this can tell another daemon where to ssh into when I invoke it remotely. So, let’s say I want to grab my WAN address in a script. I can use curl with a number of 3rd party sites (sites that often change. But, one that we can use here is ipecho.net. Here, we’ll look at their plain output page here: curl ipecho.net/plain This can then get output into a variable or file for processing in other parts of a script. For example, the output here is basically the same thing but…

  • Mac OS X,  Mac OS X Server,  Mac Security

    Caffeinate Your Commands

    The caffeinate command is pretty cool. It keeps your computer from going to sleep. It can run in a couple of different ways. There’s a timer that prevents sleep for a little while. You can also run another command from within caffeinate that keeps the system awake until the other command is finished. Here, we’ll scp a file called source file to a host called servername and keep the system from going to sleep until the process is finished: caffeinate -s scp sourcefile me:servername/targetfile Here, we’ll just use the boring command to tell the computer not to go to sleep for an hour: caffeinate -t 3600 &

  • Mac OS X,  Mac OS X Server,  Mac Security

    Disable File Extension Change Warning Dialog

    By default in OS X, when you change an extension for a file, you get a warning. This is somewhat annoying to me, as I do this pretty frequently and have never almost accidentally done so. So to disable, send a FXEnable ExtensionChangeWarning key into com.apple.finder as false: defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false To then undo, simply run with a true key: defaults write com.apple.finder FXEnableExtensionChangeWarning -bool true

  • Mac OS X,  Mac OS X Server,  Mac Security,  Mass Deployment

    Disable Unicast ARP Cache Validation In OS X

    As of OS X 10.9 (and in many cases more importantly in OS X Server for 10.9 and higher), OS X now performs ARP cache validation when trying to pass traffic over a router. If you are double NAT’d/use redundant gateways then the traffic can be interpreted as network redirection and cause some pretty bad packet loss/latency. You can disable this feature by turning off net.link.ether.net.arp_unicast_lim using sysctl: sysctl -w net.link.ether.inet.arp_unicast_lim=0 That will only disable unicast arp validation until the next reboot. If it fixes a latency problem you’re having then you can go ahead and make it permanent by adding the following line into /etc/sysctl.conf: net.link.ether.inet.arp_unicast_lim=0 If you’re still…