Alfred Workflow for Setting up Workstations

Working on several coding projects, I've seen a typical theme in how I get started. The pattern usually consists of opening all the relevant files (Repos, Trello Board, text editor, server, etc.). If I'm working on a project after a long break, takes a good minute or two remembering which files are important and getting everything setup.

Even otherwise it gets cumbersome opening all these files each time. Small loss of time and an unnecessary mental overhead which should rather be served on coding. Being the lazy developer that I am, wanted a simple hotkey I could use (typically named after the project), and like a container have everything automagically setup.

AppleScript seemed like a good candidate. I also use OneTab meticulously to launch commonly used tabs. But I knew there could be an even faster way of doing this. Since I've already purchased the pro-version of Alfred made more sense to develop my own workflow using its GUI. Alfred has strong claims with optimization, and I've enjoyed using awesome workflows developed by the community.

Having not written any workflows before, these were the steps I took:

  • Setup your keyword, best named after the project.
  • Setup multiple actions -> Open File. Mention the path of the project and select the preferred application. One action included Atom, and another with the same path for iTerm2.
  • Action -> Launch Apps/Files. Depending on your project can specify whether to launch Postgres, MAMP, what-have-you
  • Opening a new Chrome window with multiple tabs. Started a new thread chained to the parent keyword trigger in parallel to the above actions.
  • First hurdle was to figure out how to open multiple tabs instead of separate windows for each link. (Different options below) But the most straight-forward was to setup an Action (Open URL) and keep chaining the different urls you wish to use. Fortunately Alfred opened each of them in new tabs.
  • I also wanted to open a new Chrome Window for the Workstation instead of having the new tabs all display in my current browser. This is mainly because I use different profiles and desktops, and having a clean separation serves me best. To get around this, I had to use AppleScript to open a new Chrome Window. Action -> Run NSAppleScript: ``` tell application "Google Chrome" make new window tell application "System Events" to set frontmost of process "Google Chrome" to true end tell ```

    Alternate Options for Opening Multiple tabs:

    I ended up using the process described above. But here are a few other ways of opening multiple tabs in the browser of your choice.

    1- OneTab:
    Actions -> Open URL -> Paste in Shared OneTab url which holds a collection of the relevant project tabs.
    2- Run AppleScript:
    on alfred_script(q)
      set urlList to {"", "", "http://", "", ""}
    	set numURLs to (count urlList)
    	tell application "Google Chrome"
      		-- create all the tabs that are needed
      		tell application "System Events"
        		-- enter the url in the open window
        		keystroke (item 1 of urlList)
        		key code 36
        		repeat with i from 2 to (numURLs)
          	-- for each additional url, first create a tab
          tell process "Google Chrome"
            click menu item "New Tab" of menu "File" of menu bar 1
          end tell
          -- now enter the url
          keystroke (item i of urlList)
          key code 36
        end repeat
      end tell
    end tell
    end alfred_script


    3- Bash Script:
    open -a "Google Chrome"


    Future Enhancement

    This new workflow is definitely a delight to use, and spares several minutes of my life every time I sit down to get productive. For a second iteration I would like to ability to open the workstation in a separate desktop (Mac Spaces).