Sunday, December 11, 2016

Control iTunes from command line

It is possible to control iTunes from command line. In order to do so you need to install itunes-remote.
Run npm install --global itunes-remote
Now you can send commands to iTunes.
First command needs to start with itunes-remote.
This would start itunes-remote session and all following commands don't have to starts with itunes-remote
any more.
Available commands are:
help, exit, play, pause, next, previous, back, search.
So you can run commands like this:
itunes-remote search moby
Important to note here that you can only work with tracks that are part of your Library.
Command exit did not work for me. When you are using search for title that consists of multiple words
you should use single quotes like so:
itunes-remote search 'twisted transistor'
If you really want to you can start using this functionality inside of your scripts.
For example I added these lines to my pre-push git hook: 
 puts ("Pushing...pushing real good") 
 system("itunes-remote play") 
 sleep 3 
 system("itunes-remote search 'salt-n-pepa'") 
 sleep 5 system("kill $(ps -A | grep /Applications/ | awk 'NR==1 {print $1}')")
What happens here is that this script will be executed on whenever I do a push to my repo. It would open iTunes,
wait 3 seconds (this is necessary for the process to get ready for commands) and would start playing song Push It
by Salt-N-Pepa because that is the only song by this band I have in my library. After 5 seconds the scripts
would kill iTunes process.

Sunday, November 27, 2016

Install any App Store software from command line using mas-cli

   Recently I had a need to create easy onboarding setup.
   Whenever a new member joins the team I want him to be up and running with a local dev environment in a shortest amount of time. I want the process to be error prone, repeatable and involve as less manual interaction as possible. Wouldn't it be nice to just say: "Hey, run this script. And you good!"
   As a part of this effort there is a need to be able to programmatically install apps that are only distributed via App Store and are not available via Homebrew.
   Meet mas-cli utility.
   It allows you to search, install and update App Store distributed software.
   Installing mas-cli on you machine is as easy as running brew install mas in the Terminal window.
The way mas-cli works is that you first need to know the ID of the app you're interested in. You can find it by running mas search <name_here>. This will return a list of available app that have anything to do with the name you provided. Find the one you most interested in and make a note of the ID displayed next to the program name. Now you can run mas install <id_here>. And that's it. The program will be installed without you ever having the need to interact with App Store directly.
   That's cool. But what we really interested here is to come up with a way to put software installation routine in the onboarding script.
   Here is an example of how to do that if you lets say want to install Xcode:
mas install $(mas search xcode | grep 'Xcode' |head -1 | awk '{print $1}')
Here we first search the registry for xcode. Select the result that equals to 'Xcode'. Take only first column - that would be the ID. And we pass it to mas install command.

  So what left here is to add a line like this into your onboarding script. Just make sure you have mas utility installed on the machine prior to invoking such routine.

  Mas-cli GitHub page

Sunday, October 30, 2016

Why Homebrew is awesome

   Homebrew is a package manager for Mac OS. Similar to yum on Centos and apt-get on Ubuntu you can search repositories for specific software and install it on your machine using brew install package_name.
   Now, this post is about a cool feature of Homebrew I didn't know before. You can install full fledged apps that typically are distributed in a form of .dmg files right from Terminal using Homebrew.
   For example you can install heavyweight apps like IntelliJ and RubyMine by JetBrains, Atom, Chrome browser etc ... without ever leaving the Terminal, opening the browser to look for installers.
   The only thing you need to do is to specify cask option in brew command.
For example, if we want to install IntelliJ just run  brew cask install Caskroom/cask/intellij-idea
   Isn't that cool! No more looking and googling around for app's distributions and how to install it.
   Installing java is a good example. Instead of going to Oracle website, figuring out which link to press, which type of package you need for your specific need. With Homebrew you just type brew search java and once you settled on what package you like you go brew cask install Caskroom/cask/java... without ever leaving the Terminal window.
   Now, how do you know when you need to use cask option?
   Let's talk about brew search some_string. This command is used to search for available packages which have some_string in them. If the package you like to install is having cask in it - you need to use cask option.

  So let's go over an example - I want to install Chrome. Here's how it would look like:
  1. search for available packages by running brew search chrome

    seems like we want to use package Caskroom/cask/google-chrome
  2. install the package by running brew cask install Caskroom/cask/google-chrome
That's it! Chrome should be installed and available in your Applications folder.

Friday, February 12, 2016

Work on personal project

I'm a founder and sole owner of Resource is dedicated to help traders of various skill level to find practical trading info. 
Ruby on Rails - HTML - CSS - JavaScript - PostreSQL - Heroku - Git