Sync Mac Desktops

Sync Mac Desktops

Modern web worker’s workflow needs to be as efficient as possible. Part of that workflow demands that we work on multiple computers. I, for one, love to work on my iMac. I have space, both at my desk and at on my computer’s Desktop screen. When I have to leave to speak with someone or to go to a class I take my MacBook Pro. It is a very capable machine but that is all I take with me. I don’t have any peripherals like mice, keyboard, or external drives or monitors. Basically, I need an Internet connection to take notes and look up references. If I could sync my Mac Desktops I could save a lot of time. 

What’s the problem

Dropbox and Google Drive are my favorite syncing methods. These services let me share work with others. Google Drive, in particular, lets me collaborate with other people at the same time! When I’m on a team that is great.

I use my desktop as a temporary holding space for the work I’m currently involved in. It could be images that I want to upload to a website or research for a presentation. It doesn’t really matter.

Since I go back and forth between machines I needed to come up with a solution. Since the Desktop on our computers are just directories anyway why couldn’t I just link them together somehow?

Symlink all the stuff

I already use Dropbox and in that service I hold all my other syncs settings. Settings for text editors, email clients, and productivity tools are kept there. So that is what I did with my Desktops; I symlinked them to the same directory.

What is a symlink?

Basically it is a reference to another location in your operating system. When your operating goes looking for the Desktop it’ll be immediately directed to the location that resides in your Dropbox.

What happens if I can’t connect to my Dropbox account?

It won’t matter. Dropbox has placed a folder in your user directory to hold information. Your data actually lives in that location and then is synchronized up to the cloud, wherever that is.

How to do it

I’m assuming that you have a Dropbox account and that it is installed on your computer. I’m also assuming that you’re on a Mac. You also obviously have more than one machine. This process will involve some intermediary synchronizing so purge your Desktop of unnecessary items; i.e. clean it down to the metal. Move all your Desktop items to a temporary location for now.

Let’s get started.

On your first machine, open Terminal. If you don’t know it’s in Applications>Utilities.

From there you’ll need to move into your Dropbox folder. Use this command from Terminal

mv ~/Dropbox

You can identify what directory you’re in if you type: pwd

Now create the link:

ln -s ~/Desktop

Pro tip: For the really deep file paths, save yourself some headache and drag and drop from Finder onto Terminal.

Next, let any file syncing happen. It shouldn’t be much. Mounted volumes won’t sync so don’t worry about that. Ideally, your desktop is clean, anyway.

Next turn off Dropbox on your first machine. Your local symlink will exist and your Dropbox version will also exist. Remember the Dropbox version will exist in the cloud and on your local machine. Now got to your other machine. You’ll have a Dropbox folder in there that you can check to see if there is directory named Desktop. I put all my symlinked directories at the root of my Dropbox folder. From your other computer you’ll see that new Desktop directory.

Now, quit Dropbox on your second machine. Next, move into your second machine’s Dropbox folder and delete the Desktop directory. Don’t worry. If you delete a symlink it does nothing to the original files. Now go into the second machine’s Terminal and repeat the steps from above. You’re going to symlink your Desktop to that machine’s Dropbox. As in:

cd ~/Dropbox

Then

ln -s ~/Desktop

On your second machine turn Dropbox back on. Turn your Dropbox back on on your first machine. You can’t symlink to a file that already exists. It wouldn’t be symbolic, it’d be actual. You destroyed the first symlink and replaced it with an identical one. The first machine is none the wiser. It thinks it is and always has been pointing to the exact location since spelling and locations are exactly the same. Pretty sweet.  

 

Automate Local Development with BASH

I can’t afford to be inefficient at Efficiency of Movement. I am a one-man show and any wasted movement is wasted money. I started to notice that I was repeating myself more than I should have been. It was high time to automate my process even more.

Developing Locally

When I start a new project, like many other developers, I’m sure, I go out to WordPress.org download a fresh copy of WordPress and set it up manually. It is a fairly straight forward process and the development team at WordPress has done an excellent job at making it easy. They even coined the process the famous 5-Minute Installation. They’ve done their part to make it easy, the rest is up to the professional developer. This is especially true if the developer is making multiple websites a week or month. The amount of time spent on opening up applications, alone, is cringe-worthy. Much less the inconsistencies of file names, user names and profiles, installing plugins, activating, blah, blah, blah. Hours later…

BASH to the Rescue

imgresBASH scripts are not complex. At their foundation, they are a series of steps performed by the machine set in particular order. You write the script and tell the machine what to do and the machine does it. It is automation at it’s purest. I had used BASH before and knew that was powerful but combined with tools that others have created specifically for WordPress this script is now a powerhouse. I estimate that it saves 1.5 hours of development time. I wish I can only image the amount of frustration that it saves by creating with consistent naming convents and consistent file locations.

Save Time

My estimation comes from the fact that the fastest that WordPress can be installed is 5 minutes. I don’t install WordPress, I make WordPress websites and that takes considerably more time to set up. I have to create a database locally, that if done right can be used on a live server. I have to remove cruft that I don’t need like plugins and themes that come preinstalled. I have to add users and their roles to to the site. I have to add pages to the site. This script now takes care of all of that. Basically, those items are nothing more than a series of commands performed in a specific order.

I also have to add things to each site I start. I have to add my starter theme and my plugins. I have to activate some and deactivate others. Again, a script is the perfect tool to make this an automatic process.

Automate my Local Development

mamp-pro-logo-bigI don’t want to place the code in this post because it will likely change as time goes on. But, here is a link to my script, but I’ll walk you through it here, too. First I want consistency in names and locations. I prompt for the web site’s name. The user can use regular English words and spaces. The name of the web site is then used to create the rest of the variables inside of the script, such as database name, user names, and file locations. See, consistant.

I install WordPress and delete all the themes I don’t want. Then I clone into my own fork of Ole Frederick‘s fantastic starter theme, FoundationPress. I have made my own customizations that I want but that the community may not. My BASH brings down the files, runs the grunt tasks, and then opens up a browser window that is ready for my login information.

Summary

Fork my script and add your own customizations. Think about what keystrokes you are performing repeatedly. Can those keystrokes be performed by a machine? If so, then you should really get a script to do it for you. That way you can get back to solving the more interesting problems of web development.

An Efficient Fonts and Hazel Workflow

Hazel and Fonts

I have always had a problem with fonts. I love to have them, I love to look at them, but most of all I love to collect them. I recently started a project and needed a font that I didn’t have. Off I went to find it. Luckily, it wasn’t very far away, only at Google Font’s. Then I started seeing more free font giveaways in my RSS feed. That’s when I discovered my real problem, collecting the fonts in my Downloads folder.

I knew I had a problem when I first noticed that I was repeating the same steps over each week when a new font came out. Hazel to the rescue.

I set up this little workflow to look at the .zip files in my Downloads folder, identify where they came from, unzip, extract, and sort the contents.

The workflow takes care of everything for me. Now, when I see the fonts I just click download and the rest is handled for me, the way computers should work. The one caveat is if the fonts source URL is not in the Hazel script I have to add it. But that is not repeat a step now is it.


 Titles of the four rules that make this work

 

Four rules to manage fonts with hazel
The titles of the four rules that make this a handy workflow.

 

Source URLs

The first thing Hazel needs to do is unzip the file…if it came from the right source. I have only a few source URLs now but as I find the fonts I want to download I will add those specific URLs to the rule. I could probably front load them now but why? I’ll cross that bridge when I get to it.

Unzip files with Hazel based on file type and file source.
The unzip rule. I based my search and find criteria on type of file (archive) and whether it came from a specific source.

Look at what was unzipped

Now that Hazel has unzipped the correct files, she needs to do something with them. This rule looks for file extensions matching common font file extensions. Before she is done, Hazel renames the parent folder of the font files. This is important to remember. The rename will be used later.

Hazel finds and moves any files with font extensions
Hazel renames the parent folder

Again, I am sure I am missing some extensions and I can always go back and add them. This list is a little more finite then the previous list of URLs so maybe I should take a look at Wikipedia and just add them now.

Time to move

Hazel moves only the font files to my specified fonts folder. This is a pretty standard Hazel operation. Notice a nice notification at the end of the move, too!

move-any-font-ext-that-hazel-finds-2

Don’t forget the trash

An important part of automation is the trash management. In this workflow, I added a delete-- to the beginning of the file in the previous step. Now, Hazel sees that delete-- and deletes that folder. Otherwise the trash would remain.

Trash Files Appended with delete--
Trash Files Appended with delete-

 Conclusion

As with many things, this is a work in progress. I still have yet to find every URL that I may find a font from. But, I think it is a solid, time-saving workflow. I hope you get a lot of utility out of it. The one thing I wish it could do is track the time I save by not having to perform each step manually.

Font-Downloads.hazelrules