Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using kramdown to convert my markdown-formatted source files into html. The command I've been using is:

kramdown %filename | Out-Clipboard

(Out-Clipboard is from the fantastic PSCX. This means my formatted html is immediately ready to paste into another program or editor)

I'd love to streamline this process and be able to use a context menu item to do the same thing, instead of opening a shell and typing out the command each time. What's the best way to pass these instructions to powershell, and add it as menu option?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You can run PowerShell commands from the command-line (batch files, etc.) by using this format:

C:\> PowerShell <PowerShell command you want to run>

ie: C:\> PowerShell "kramdown MyFileName.txt | Out-Clipboard"

So we can use that in a context menu entry.

For simplicity here's how you can add a new Context Menu command to run it against whichever file you have selected/right-clicked (this is probably not the ONLY way to do this):

  • Head to HKEY_CLASSES_ROOT\*\shell in the registry.
  • Create a new Key named what you want (like say "Kramdown").
  • Set the "Default" REG_SZ value of that new key to the text you want to appear on the context menu (like say "Kram This Down").
  • Create another new Key inside the key you just made, and name it "command".
  • Set the value of the "Default" REG_SZ in that new 'command' key to run the command you want.

The command you'll want to enter is like above, only we need to tell it to do it in the command prompt, and use the %1 variable so it knows the file you clicked on:

cmd /C PowerShell "kramdown %1 | Out-Clipboard"

The /C causes the CMD window to close after it's done.

As soon as you make these registry changes they will affect the context menu, so you don't need to logout or reboot to enable or test your changes.

Since I don't have your source files, Kramdown, or Out-Clipboard I can't test this 100%; but this should be enough info to get you going, if it doesn't 'just work' as-is. :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.