SkillAgentSearch skills...

XCActionBar

"Alfred for Xcode" plugin

Install / Use

/learn @pdcgomes/XCActionBar

README

XCActionBar -Xcode plugin

tl;dr

If you use Alfred, LaunchBar, QuickSilver or other similar products (and if you don't, you really should!), then you already know what this is all about.

Else, if you haven't and you are at least familiar with "Open Quickly" (default CMD+Shift+O), then you also know what this is all about -- it's like "Open Quickly" but for all menu bar actions, code snippets, unit tests, custom built-in actions that can operate on text or any other kind of custom action you'd like (just as long as you implement it)

Else Read along ... :)

Xcode 9 support

XCActionBar is at present only partially supported in Xcode 9. The vast majority of custom actions operate on text and therefore require access to Xcode's internal text views which have changed significantly in Xcode 9. I know of a few other plugins in a similar situation and people are hard at work trying to figure out what the new hook points are. I'm currently not in a position where I can dedicate a lot of time to research this, but I will definitely get to it at some point.

Important notes on Xcode 8

Xcode 8 introduces a new extension system which enables developers to finally be able to build and distribute Xcode extensions. The drawback is that at the present time this breaks the system we've had in place until now, meaning XCActionBar (along with all other plug-ins) will stop working. Given how sparse the documentation is, it isn't clear whether most of XCActionBar's functionally can be ported over to the new system; I suspect it is not, at least not just yet. In the meantime, while not pretty, there is a workaround which will allow Xcode 8 to still load all your plugins, please check https://github.com/alcatraz/Alcatraz/issues/475 for more information. Do keep in mind that this solution is inherently unsafe and definitely not the way forward, so use your judgement.

###Updates: If you'd like to keep up to date with the latest feature additions, keep an eye on the changelog page.

###Demo:

For more demos, please check out this page, we'll be updating it over time.

Sorting lines demo: image

Built-in Add Prefix to Line(s) and Add Suffix to Line(s) demo: image

Built-in Surround With NSNumber Literal and Surround With NSString Literal demo: image

###Installation:

The recommended installation method (and also the simplest) is via the Alcatraz plugin manager. Just follow their installation instructions, search for XCActionBar, click install and you're done!

Alternatively you can run the following command in your terminal:

curl -fsSL https://raw.githubusercontent.com/pdcgomes/XCActionBar/master/Scripts/install.sh | sh

A lot of people recommend against blindly executing shell scripts (and rightly so!), so I'd make sure to open the script first and ensure it won't delete all of your files or worse - it's good practice. If you don't feel comfortable, there's one final option:

Download or git clone XCActionBar, open the project in Xcode and simply build it. The plugin will be automatically installed. Just make sure to restart Xcode once you're done.

###Motivation:

I always try to accomplish as much as I possibly can without ever moving my hands away from the keyboard, there's simply no other means of input that feels quite as natural or efficient. Shortcuts are great, but there's only so many combinations of keys the average person can memorize. On top of that, the more shortcuts you have, the more likely you are to have to rely on multiple modifier key combinations, which may not always make them very comfortable to type.

It's much simpler and natural to type commands that actually describe what you want to achieve. I'm sure most people will agree that it's quicker to type fold or unfoldthan it is to type a four-key shortcut (which is basically as long as typing foldand probably doesn't feel as natural).

Note: This is preliminary documentation as this is very much work in progress.

###What can it do?

Here's the executive summary in three simple examples:

Example #1: Built in actions

  1. Place the carret on the line you'd like to move up
  2. Double tap CMD or press CMD+SHIFT+8
  3. Type mlu or m l u
  4. Return
  5. Double tap ALT or press CMD+ALT+7 to repeat the last action as many times as you'd like (this works for any action)

Example #2: Custom actions

  1. Select a block of text
  2. Double tap CMD or press CMD+SHIFT+8
  3. Type nsl
  4. Return

Notice as the selected block of text is automatically surrounded with NSLog(@"your text selection") Hint: type surround for a list of available "Surround Text With" actions

Example #3: Code snippets

  1. Place the carret where you'd like to expand the snippet
  2. Double tap CMD or press CMD+SHIFT+8
  3. Type inline
  4. Select C inline block as variable
  5. fuckingblocksyntax.com suddenly becomes less necessary

Hopefully these short examples showcase some of the features XCActionBar currently supports. I'll continue adding features and making things generally better, so expect lots of changes in the coming weeks.

Searching

Action search currently operates on a few data sets:

  • Menu Bar items and sub-items (recursively)
  • Code snippet library (system and user-defined)
  • Custom plugin vended actions

The current searching strategy is very simple and naive but does the job quite effectively. While it doesn't yet support fuzzy matching, it's quite flexible in how it handles partial matches. Take a look at the examples above for a few examples. I'll be working on improving this very soon, but at this stage it does seem to be quite effective.

To bring up the action bar, type in the default shortcut CMD+SHIFT+8 and enter your search terms. After performing an action, you can repeat it by typing in the repeat command shortcut CMD+ALT+7.

UPDATED:

  • You can now present/dismiss the acion bar by simply double pressing CMD quickly
  • You can now repeat the last executed action by simply double pressing ALT

The original shortcuts still work. I've also added a general configuration file XCSurroundWithActions which can be used to tweak these two shortcuts -- currently it only supports the following:

NSAlternateKeyMask
NSCommandKeyMask
NSControlKeyMask
NSFunctionKeyMask
NSShiftKeyMask    

This is all very much experimental so do expect changes.

Actions

As mentioned above, the plugin comes bundled with a few custom actions. Following is a catalog of all of them and a short summary of what they do:

  • XCAddPrefixToLinesAction prepends the string contents of the pasteboard to each selected line

  • XCAddSuffixToLinesAction appends the string contents of the pasteboard to each selected line

  • XCCopyActiveDocumentFilePathAction copies the active file path to the pasteboard. Supports file://, POSIX and POSIX escaped (useful for copying to the terminal)

  • XCCopyActiveDocumentDirectoryAction copies the active file directory to the pasteboard. Supports file://, POSIX and POSIX escaped (useful for copying to the terminal)

  • XCDeleteBlankLinesAction deletes all empty strings in the selected range

  • XCDeleteLineAction deletes the line the carret is currently positioned in

  • XCDuplicateLineAction duplicates the line the carret is currently positioned in, or the selected lines

  • XCJoinLinesAction joins the lines across the current selection. Lines are joined via a delimiter (default is space but can be user defined)

  • XCSplitSelectionIntoLinesAction splits the current selection(s) into lines by delimiter (default is , but can be user defined)

  • XCSortSelectionAction performs line sorting (ascending or descending) of the selected lines

  • XCSurroundWithAction surrounds the selected text block with an arbitrary prefix/suffix

  • XCSurroundLineWithAction surrounds each selected line with an arbitrary prefix/suffix

  • XCTrimWhitespaceAction trims whitespace for each selected line (supports leading; trailing or both)

  • XCOpenActiveDocumentPathInTerminalAction opens the active document's directory in the terminal app (currently supports iTerm.app and Terminal.app but more can be added in XCActionBarConfiguration.plist under XCSupportedTerminalApplications

Text selection actions

There are also a few actions that deal with text selections:

  • XCSaveTextSelection
  • XCLoadTextSelection
  • XCClearTextSelection
  • XCMoveSelectionHere

These allow you to select non-contiguous text selections using only your keyboard by selecting a chunk of text (as you would), but with the difference that you can then save the selection -- this will mark the text in orange (color will be customizable soon), you can then proceed and make additional selections. When you're done, just load selection which will cause the marked text to be fully selected. You can then apply any text action as you would for normal selections. Two more things: at the time of writing, the marked text will not automatically unmark itself, so you need to clear selection. Also, you can undo marking/unmarking of the text, which is pretty cool.

XCMoveSelectionHere allows you to quickly collect chunks of text and then move them to one place in one swift action - no more clunky mouse selections or multiple {cut, copy}/paste trips.

Surround With actions

I've bundled a few XCSurroundLineWithAction and XCSurroundWithActionS:

  • Autorelease pool @autoreleasepool { ... }
  • Square Brackets [ ... ]
  • Curly Braces { ... }
  • Inline Block void (^BlockVariable)(void) = ^{ ... }
  • NSLog NSLog(@" ... ")
  • NSNumber @( ... )
  • NSString @" ... "
View on GitHub
GitHub Stars1.2k
CategoryDevelopment
Updated2mo ago
Forks36

Languages

Objective-C

Security Score

100/100

Audited on Jan 27, 2026

No findings