Last Updated: February 25, 2016
·
1.834K
· ericrallen

Easily Generate xip.io URLs for Pow Projects

I just got Anvil up and running and wanted to be able to easily share my .dev URLs across our local network.

After learning about xip.io, I wanted to be able to quickly generate these URLs so that I could send them to my co-workers.

To do this, I created an AppleScript that sits in my ~/Sites folder and that I symlink in each of my project folders.

EDIT: I accidentally copied and pasted the AppleScript from a version that was incorrect instead of the final, working version. I have updated the code below and updated the gist.

Here's the AppleScript:

-- generates xip.io url
-- I store this script in my ~/Sites directory and then use `ln -s ~/Sites/xip.io.scpt` in Terminal to create a symbolic link in the folder for my site
-- add this alias to your .bash_profile or .bashrc for quickly using it via Terminal:  `alias xipit='osascript xip.io.scpt'`

-- get IP address
set tIP to do shell script "ifconfig en0|grep 'inet '|cut -d ' ' -f 2"

if(tIP is "") then
    set tIP to do shell script "ifconfig en1|grep 'inet '|cut -d ' ' -f 2"
end if

-- get current directory
set currentDir to do shell script "echo ${PWD##*/}"

-- set url
set urlString to "http://" & currentDir & "." & tIP & ".xip.io"

-- add url to clipboard
set the clipboard to urlString

do shell script "echo " & urlString

Here it is as a gist.

This automatically copies the xip.io URL to your clipboard.

To make this even quicker, I set up a simple alias in my ~/.bashrc:

alias xipit='osascript xip.io.scpt'

I use Powder to set up my projects with Anvil, so I have another alias that symlinks the xip.io.scpt file into my current project, sets up Pow for the current project, and then opens the Pow URL in my browser.

alias powdvil='ln -s ~/Sites/xip.io.scpt; powder link; powder open'

But, you can manually symlink the AppleScript into your project folders, or automate it via some other command that you run a lot.

With this symlink, you can just type xipit into your Terminal while you are in the folder for the project whose link you would like to share and the xip.io URL will be automatically copied to your clipboard.