How can I use a bash script as a Service in OS X without having to set it up trough automator? I'd basically like to write a bash script, save it in ~/Library/Services and then just have it show up in the services menu. Thoughts?

link|improve this question

The mac tag is for questions about Mac hardware. While the osx tag is for software. Choose one or the other. – Wuffers Apr 5 '11 at 0:32
feedback

3 Answers

up vote 3 down vote accepted

ThisService is a bit more streamlined than Automator:

thisservice


The built-in script menu can also be used to run shell scripts:

script menu shell scripts

It can be enabled from AppleScript Utility — Preferences — Show Script menu in menu bar. It includes files in ~/Library/Scripts/ and optionally /Library/Scripts/. You can't assign shortcuts though — that's the main reason to use FastScripts instead.


Some applictions for just assigning shortcuts: osx - Bind a key to a commandline command in Mac OS X? - Super User.

link|improve this answer
Do you know whether it's actually different from an Automator service (e.g. performing better), or just a different implementation of the same idea/different GUI? Can it be automated or controlled from command line? – Daniel Beck Mar 31 '11 at 18:15
@Daniel I haven't really used either ThisService or Automator services. But one nice feature of TS is that it keeps either the original script file or an alias to it inside the .service bundle. Also there's obviously no .wflow file. I meant more streamlined as in more focused on creating services, and requiring less steps to do so. Even though that's not necessarily true if you have quick access to a saved Automator workflow or are using its AS dictionary or something. – Lri Mar 31 '11 at 19:11
feedback

I don't know of a way to do that directly. Aside from Automator, you can also use XCode to build an AppleScript wrapper for your script that will work as a Service.

Using the script directly is more problematic. My understanding is that it needs to be an app bundle, and then it needs specific entries in its Info.plist telling the system what service it offers. The former can be done with Platypus; for the latter, use the Property List Editor in XCode (or plutil and an XML editor if you hate yourself like playing with XML directly) to craft an NSServices key.

This leaves the rather big question of how to invoke it; the Objective-C message created from NSServices key NSMessage isn't going to be understood directly by a shell, and it looks like Platypus doesn't have a way to receive it either. I suspect that means writing a custom wrapper in Objective-C.

link|improve this answer
feedback

You should consider trying FastScripts. It's like OS X's scripts menu done right, including keyboard shortcuts for easy access.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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