Saturday 8 October 2016

Getting some plugin functionality back into Xcode 8

One of the big losses in Xcode 8 was the plug-in ecosystem in previous versions most easily leveraged by installing Alcatraz (R.I.P)

 Raise them radars if theres some functionality you want back and you might see it in Xcode 9

 In the meantime if the underlying functionality of your plugin can be expressed as command line utility you can use Automator.

Step 1.

Launch Automator and create a new Service.


Step 2. Setting Up


To do whatever it is you want your thing to do on the command line add a Run Shell Script action.




Unless you are a magician whose shell scripts do exactly what you intended first time you will need to add  a  Get Specified Text action to test things out.


You'll discard the Get Specified Text action before you finally save.

Step 3. Do the thing 

In my case I want to be able to search in Dash quickly. Luckily Dash has a URL scheme 

dash://{search phrase}

I use the naive implementation and pass the composed string to open

SEARCHTERM=`cat`
/usr/bin/open dash://$SEARCHTERM


Hit run and lets see.




It doesn't like spaces...

So I just need to transmogrify the selected text to URL encoded format. So I dive into the fount of infinite knowledge and come up with

SEARCHTERM=`cat`
SEARCHTERM=`python -c "import urllib, sys; print urllib.quote(sys.argv[1])" "$SEARCHTERM"`
/usr/bin/open dash://$SEARCHTERM

Which gives me.


Hurrah.

Step 4 - Save it and assign a key shortcut

Delete the Get Specified Text action and save your Automator flow and give it an appropriate name that you'd like to see in a menu.

It will be saved in the correct folder for you (in ~/Library/Services)

Now when you select some text in Xcode you'll be able to see this in Xcode > Services



But really you'll want to do this with a key shortcut.

Open up the Keyboard settings panel and go to the Shortcuts tab. Select App Shortcuts


Press + and enter the Exact Case Sensitive name of the menu command ( the name of your action file )

Select the Keyboard Shortcut field and use the key combo that you want.


You may find your desired key combo is already in use so it might take a couple of tries to get one that's unique.

Now you can use the key command to search in Dash whenever you select some text.



2 comments:

  1. The instructions are unhelpful, I'm glad I only wasted 7 dollars on this.

    You need a decent getting started guide.

    ReplyDelete
  2. What would you like to know about?

    ReplyDelete