Shell script Mac Apps(mathiasbynens.be)
mathiasbynens.be
Shell script Mac Apps
http://mathiasbynens.be/notes/shell-script-mac-apps
17 comments
Wow! Any good collection of things you can do with open?
I have a small script named `pman'
#!/bin/bash
man -t $@ | ps2pdf - | open -fa Preview
it opens a man page formatted as a PDF in PreviewOpen .
This opens the current directory in finder. I use this one all the time.
This opens the current directory in finder. I use this one all the time.
`open http://google.com` will open a URL with your default browser.
Here is something you can do with man: type 'man commandname' to get a description of things you can do with commandmame.
This may not work as intended in cases where a command has the same name as a function. The nicely recursive 'man man' will tell you how to work around that.
This may not work as intended in cases where a command has the same name as a function. The nicely recursive 'man man' will tell you how to work around that.
You seem to be missing that the value is in combinators. See the PDF trick above for an example of something not covered in the man page.
"Not covered in detail". From the man page:
Also, the man page has several IMO more interesting examples than this "make a new mail from the command line, but you will have to use the GUI to fill in the destination address and to click 'Send'".
For example, I did not know about "open -f", "open -n -W", and "open -h".
"open -a /Applications/TextEdit.app '/Volumes/Macintosh HD/foo.txt'"
opens the document in the application specified (in this case, TextEdit)
That is exactly what the example does. The only thing that may be slightly surprising is what Mail.app does when you drag a .pdf on it. But that is only slightly surprising; the only alternative I can think of is that it would beep and do nothing else.Also, the man page has several IMO more interesting examples than this "make a new mail from the command line, but you will have to use the GUI to fill in the destination address and to click 'Send'".
For example, I did not know about "open -f", "open -n -W", and "open -h".
Actually, the there is a reason why I use the short form - the rest of the workflow is also completely keyboard based:
`open -a Mail mypdf.pdf` opens an email window that has the focus and the cursor in the "from" field, with address book access and all. From there on, it is:
- Type the first letters of the contact to sent to - Tab to "Subject", write Subject - Tab to Body, write the Body - Command-Shift-D
Includes all (legally needed, yawn...) signatures, my S/Mime-setup and has full access to my address book. Sure, its simple and the equivalent of dragging the pdf to the Mail icon, but damn quick.
`open -a Mail mypdf.pdf` opens an email window that has the focus and the cursor in the "from" field, with address book access and all. From there on, it is:
- Type the first letters of the contact to sent to - Tab to "Subject", write Subject - Tab to Body, write the Body - Command-Shift-D
Includes all (legally needed, yawn...) signatures, my S/Mime-setup and has full access to my address book. Sure, its simple and the equivalent of dragging the pdf to the Mail icon, but damn quick.
This seems more cumbersome than opening AppleScript Editor, writing the following, and saving the script as an app.
do shell script "my script"
Despite being an obnoxious language, AppleScript is pretty handy for distributing shell scripts onto non-technical users' machines.I've recently fallen in love with Automator. Although it make have a few limitations, you can get around it by embedding AppleScript or Python.
In two minutes I made a quick and dirty system wide workflow to download the selected URL.
In two minutes I made a quick and dirty system wide workflow to download the selected URL.
For basic GUI interaction, there's also cocoaDialog:
http://mstratman.github.com/cocoadialog/
http://mstratman.github.com/cocoadialog/
see also - http://sveinbjorn.org/platypus
Yes, please use Platypus instead, it'll save you a lot of trouble. The article's solution is very hackish and as you can tell from the comments you'll run into lots of issues.
It's a lot easier than the original post says (and it's mentioned in the comments). Just rename your shell script to end in `.command` and you can have it execute via a double click (or launch it with launchbar/quicksilver). I have this in my .zshrc to automatically create a new .command file for the current directory so I can easily open it up in MacVim:
https://gist.github.com/3474341
https://gist.github.com/3474341
[deleted]
`open -a Mail mydoc.pdf` (open Mail and create a Mail with attachment mydoc.pdf)
is my favorite line of Mac shell magic ever.