Skip to content

Instantly share code, notes, and snippets.

@miketucker
Created October 10, 2013 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miketucker/6919579 to your computer and use it in GitHub Desktop.
Save miketucker/6919579 to your computer and use it in GitHub Desktop.
mac-for-installation.html
```
title: Running an installation on a Mac
layout: post
tags: ['dev','osx','post']
```
A quick guide for designers and newcomers to the world of installations. This article explains how to prepare your Mac its first run. We also briefly look at Launch Agents and Applescripts. Bash gurus need not apply.
*Version 1.0 - October 8, 2013*
----
## Intro
The Mac Mini in recent years has become a go-to machine for installations. It's light, portable, relatively cheap, and runs a stable operating system. It might not push much in the graphics department, but for a lot of cases it's plenty good enough.
In addition to the stability of OSX, we can easily add bash scripts to the equation along with launch agents and applescripts.
----
## Table of Contents
1. [Basics](#basics) - First things first.
* Energy Settings
* Assistive Services
2. [System Tweaks](#systemTweaks) - Quick changes you'll want to make.
* Disabling Bluetooth Assistant
* Disable persistent apps after relaunch
* Disable Dashboard
* Hide the desktop
3. [Launch Agents](#launchAgents) - Quick and easy way of running apps
4. [Applescript](#applescript) - Adding a bit more control
5. [Conclusion](#conclusion) - Putting it all together
----
## The Basics <a id="basics"></a>
These are some obvious, but easily forgotten steps that should be made first.
### Energy Settings
We don't want the computer to sleep.
![Energy Settings](energySettings.png)
However you may want to add a Schedule to shut down and start up at a certain time of the day.
![Energy Settings](schedule.png)
We don't want the screensaver to show up.
![Screensaver](screenSaver.png)
We want the computer to automatically login to your user account
![Autologin](autoLogin.png)
<a id="assistiveServices"></a>
### Enable Assistive Services
If you decide to use Applescript, this will make commands much easier:
![AssistiveServices](assistiveServices.png)
----
<a id="systemTweaks"></a>
## System Tweaks
These are various tweaks to OSX that will save you some headaches.
To use: Copy and paste the code into a new Terminal window.
To reverse these commands: simply swap out the `false` with a `true` or a `NO` with a `YES`
### Disable Bluetooth Assistant
If a Mac starts up with no keyboard or mouse attached, it will try to find a Bluetooth option instead with a big dialog popup. Obviously this will become problematic for a public installation.
``` bash
defaults write /Library/Preferences/com.apple.Bluetooth BluetoothAutoSeekKeyboard -bool false;
defaults write /Library/Preferences/com.apple.Bluetooth BluetoothAutoSeekPointingDevice -bool false;
```
### Disable persistent apps after relaunch
Lion introduced the idea of windows that reopen after restarting your computer. This can cause some unexpected results in an installation environment, I'd recommend turning it off.
`defaults write -g ApplePersistence -bool no`
### Disable Dashboard
If you're not familiar, Dashboard runs those widgets that you probably never use.
This will save you some resources.
`defaults write com.apple.dashboard mcx-disabled -boolean YES`
### Hide the desktop
`defaults write com.apple.finder CreateDesktop -bool false`
----
## Launch Agents <a id="launchAgents"></a>
If you simply need to launch an app on startup, and then ensure it remains open. A launch agent will likely solve that problem for you.
### An example file:
`com.yourCompany.yourApp.plist`
``` xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.yourCompany.yourApp</string>
<key>ProgramArguments</key>
<array>
<string>Applications/YourApp.app/Contents/MacOS/YourApp</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
```
* `KeepAlive` - tag ensures that if your app crashes, it's immediately relaunched.
* `RunAtLoad` - key will launch your app on startup.
### To install
Copy `com.yourName.yourApp.plist` to `~/Library/LaunchAgents`
### To enable:
Enable: `launchctl load -w ~/Library/LaunchAgents/com.yourCompany.yourApp.plist`
Disable: `launchctl unload -w ~/Library/LaunchAgents/com.yourCompany.yourApp.plist`
----
## Applescript <a id="applescript"></a>
If you need to schedule your Mac to startup at a certain time of the day, you'll also need some sort of automated way to launch the required apps and services. Applescript is great for this kind of thing. Here are some common tasks:
First, open **AppleScript Editor.app**. It's located in `/Applications/Utilities`
### Calling a bash script:
If you've used shell scripts in the past, the first thing that will come in handy is being able to call them.
do shell script "killall NameOfYourApp"
### Catching Errors:
There's going to be a fair amount of trial and error at the beginning, so be sure to find the errors when they happen.
``` applescript
try
do shell script "killall NameOfApp"
on error
display dialog "Uh oh. Something went wrong."
end try
```
### Delays:
If you're planning to use your applescript on system startup, one thing you'll need to consider is how long it takes applications to load, etc. Delays, although not ideal, are a quick way to compensate for this.
``` applescript
delay 1
do shell script "open -n ~/Desktop/NameOfApp.app"
delay 4.0
display dialog "All done!"
```
### Sending keystrokes and manipulating windows:
This one requires that you [enable Assistive Devices](#assistiveServices) in your System Preferences.
Afterwards, you can do things like this:
tell application "System Events" to tell application process "NameOfApp"
set position of front window to {2500, 100}
keystroke return
end tell
### Exporting your script as an App
This will make it easier to trigger via **SSH** or as a **Login Item**
![AssistiveServices](exportApplescript.png)
### Run it at Startup
Lastly, you'll want to run your new Applescript app on login.
![AssistiveServices](loginItem.png)
----
## Wrapping Up <a id="conclusion"></a>
So by now you've either chosen either an Applescript app, or basic Launch Agent. If there are other methods, please let me know. Or if you have problems or suggestions, please feel free to leave a comment or submit a pull request on the repo.
Thanks!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment