Open a file in Sublime Text via OS X Terminal

If you’re working in Terminal and would like an efficient command to open a file in Sublime Text 2 — as in subl filename.html — here’s how to set it up.

I’ve now edited this post to begin with my favorite method, using an alias, then added a few more notes on creating handy aliases. Last is an alternative method which requires creating a symlink to Sublime Text’s own terminal connection.

Creating an Alias

This, for me, is the easiest method. We’ll create an alias for the basic Terminal command to open a file in Sublime Text 2, which would be: open -a Sublime Text 2 newfile.html

Here’s how to set up an alias so that you only have to type: subl filename.html

From Terminal …

1. Edit the bash profile, by typing:

vim .bash_profile

2. Then type i to insert.

3. Insert this line:

alias subl='open -a Sublime Text 2'

This creates a new shorter version of the longer command. Typing subl will do what’s after the equal sign!

4. Hit the **Escape** key to stop editing.

5. Type :wq to save and quit the editor.

6. Type exit to exit the terminal session.

7. Quit Terminal and restart it.

8. Type subl filename.html to open the desired file in Sublime Text!

To create more aliases, you can now do it by editing the .bash_profile in Sublime Text. Just type: subl .bash_profile

On the Topic of Aliases

Here are a few similar aliases I set up, by adding them to my .bash_profile, to efficiently open files in Firefox, Chrome, Safari, navigate to a frequently used directory, etc.

# Open a file in Sublime Text 2
alias subl='open -a Sublime Text 2'

#Edit Bash Profile in Sublime Text 2
alias bashprof='subl .bash_profile'

# Open a file in desired browser
alias ff='open -a Firefox'
alias chr='open -a Google Chrome'
alias saf='open -a Safari'

# Open file in Firefox, Chrome, and Safari
function testall { ff $1; chr $1; saf $1; }

# Shortcuts to directories
alias home='cd ~/'
alias nodeplay='cd ~/Nodeplay'
alias github='cd ~/Github'
alias sites='cd ~/Sites'

# Change to and list contents of a directory
function cdl { cd $1; ls; }

This Lifehacker post was helpful in the quest:
Become a Command Line Ninja With These Time-Saving Shortcuts – Lifehacker

Another Approach Using a Symlink

Back to the topic of opening a file in Sublime Text 2 — it’s amazing how diverse and confusing are the opinions on this topic. The alias approach (above) seems easiest (and least frequently mentioned). Here is another method that uses a symlink, for those who prefer it.

 

1. Create a directory named bin in your user home directory.

Create bin directory

Now we need to create a symlink in this new directory …

 

2. In Terminal, enter the following line and hit return:

ln -s /Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl ~/bin/subl

This creates a symlink called subl. You’ll see it in Finder inside your newly created bin directory.

Sublime Bin Symlink

Next to add this new directory path to your Terminal bash profile.

 

3. In Terminal, open the bash profile in the vim text editor:

vim .bash_profile

 

4. Then type i to insert:

i

 

5. Type this new export path at the cursor:

export PATH=$PATH:~/bin

Sublime Export Path

 

6. Now hit your keyboard’s Escape key to stop editing.

 

7. Save the file by typing :wq and pressing Return:

:wq

[Press Return]

 

8. Exit the terminal session by typing:

exit

 

9. Quit Terminal, then restart it.

 

10. If you need a quick file to test, you can create it via Terminal:

touch newfile.html

 

11. Now open your new file in Sublime Text by typing:

subl newfile.html

This should be your result!

Sublime File Opened

 

12. To change the command for opening a file in Sublime Text …

Simply change the name of the symlink in your bin directory. For instance, you could change the symlink name to sublime, and then type sublime newfile.html in Terminal to open your desired file.

Sublime Symlink Name Change

 

Spot an update?

Let me know if you spot anything that needs updating or clarification.

 

Credit

Piecing these steps together from available online resources took a bit of work.

Helpful bits can be found in the Sublime Text docs, and in this gist by artero.

Credit for piecing together a working combo goes to @piperseth.

LESS – CSS Syntax Highlighting in Panic Coda

To turn on syntax highlighting when working with LESS files in Panic’s Coda (I’ve not upgraded to 2 yet):

  1. Preferences
  2. Editor
  3. Near bottom of that dialogue window, under Custom Syntax Modes: , press the +
  4. Type “less” for the extension
  5. For the Syntax Mode, pull down and select CSS.
  6. Press Okay.
  7. Close Preferences
  8. Re-open your LESS files. After opening, they should be highlighted like CSS files.

That’s it.

Many thanks to Bucsa Silviu for his tip!

Screenshots

coda-custom-syntax-modes

coda-extension-less

 

Delete photos from your iPhone in 8 Steps

Once you’ve imported your photos, you may find yourself wanting to reduce a few (or a few thousand) of the ones you’ve left on your iPhone. Here is how to delete them:
  1. Connect the iPhone.
  2. Open Spotlight and type in “Image Capture.”
  3. Launch Image Capture.
  4. Click on the iPhone icon in the left hand column.
  5. The iPhone’s camera roll appears.
  6. Command-Click each photo you want to delete. Or use shift-click or Command-A to select multiple photos or all.
  7. Click the Delete Icon at the bottom on the Window

The deletion process begins. (If you’re deleting hundreds or thousands of photos, it will take a bit.)

via How do I delete photos from iPhone…: Apple Support Communities.

When iPhoto Stops Working in Snow Leopard: Here is what to do

Several Mac users have reported iPhoto problems in OS X Snow Leopard, where the app refuses to open or crashes. Here is what to do.

  1. Put the iPhoto.app in the trash (Drag it from your Applications Folder to the trash)
  2. Go to HD/Library/Receipts and remove any pkg file there with iPhoto in the name
  3. Re-install.
    • If you purchased an iLife Disk, then iPhoto is on it.
    • It will also be on the System Restore disks that came with your Mac. Insert the first disk and opt to ‘Install Bundled Applications Only…’
If that fails, then try:
  1. Trash the com.apple.iPhoto.plist file from the HD/Users/ Your Name / library / preferences folder.
  2. You’ll need to reset your User options afterwards. (These include minor settings like the window colour and so on.)
  3. If you’ve moved your library you’ll need to tell iPhoto where this is.

If that also fails:

Post the Crash Log in Apple Support.

  1. Get the crash log from Home / Library / Logs / Crash-Reporter / iphoto.crash.log
  2. Double click on the file and it will open in the Console.
  3. Copy and Paste the contents here, at bottom of this discussion.

From: iPhoto won’t open since Snow Leopard…: Apple Support Communities.

iA Writer’s Typography and Color Scheme

For those who love iA’s Writer app, Justin Blanton has examined details of its visual and typographic design:

  • Background: f5f6f6 (rgb(245,246,246)) with a touch of noise
  • Font Color: #424242 (rgb(66,66,66))
  • Font: Nitti Light
  • Line Height / Leading: 1.5

Read more here: How to make any app look like iA’s Writer — Justin Blanton — Hypertext.net

Mobile Apps Surpassing the Web?

for the first time ever, daily time spent in mobile apps surpasses desktop and mobile web consumption.  This stat is even more remarkable if you consider that it took less than three years for native mobile apps to achieve this level of usage, driven primarily by the popularity of iOS and Android platforms.

via Mobile Apps Put the Web in Their Rear-view Mirror — June 20, 2011 — Flurry.com

Fantastic Mac Productivity Apps in One Great Bundle

Fantastic Mac Productivity Apps in One Great Bundle

[UPDATE: THIS DEAL HAS NOW EXPIRED]
envato-freelance-mac-app-300x250

I’ve had several pieces of productivity software on my list for awhile now. Envato just rolled a bunch of them together into a fantastic bundle.

Normally I can find reasons to pass on a bundle, but not this one. It includes too many apps I’ve been waiting to pull the trigger on:

  • 1Password — safe, secure password management
  • Billings — professional billing for anyone
  • TextExpander — the highly touted typing shortcut utility (a favorite of David Pogue)
  • WriteRoom — distraction free writing software
  • Arq — online backup utility
  • LittleSnapper — screenshot and website capture utility
  • Radium — convenient internet radio player
  • Alarms — intuitive task management — integrates with iCal

The deal lasts until June 29.

View the Envato Freelance Mac App Bundle