+48
Planned

command line integration

Rui Carmo 12 years ago updated by fernandotcl 6 years ago 13 1 duplicate

I can't live without terminal integration of some sort. What about a way to invoke Textastic from the command line?

Duplicates 1

I'll have a look at how this can be done for a sandboxed Mac App Store app.


Which command would you prefer? "textastic" or something else? (TextMate uses "mate" for example)

+5

Not picky, really. David's suggestion prompted me to try


alias tt='open -a Textastic "$@"'


Which works, although I'm not married to that name :)

+1

Here are quick fixes.  Fix one is very simple and I use it for Mou.  This works if you substitute Textastic for Mou.



#!/usr/bin/env bash
# Open Mou markdown editing application.
open -a Mou "$@"
and more complex that looks at options and where app is installed.  This is 'mvim' for macvim.  Also looks at name so other names can be symlinked to this shell script, like 'vimdiff'.

#!/bin/sh
#
# This shell script passes all its arguments to the binary inside the
# MacVim.app application bundle.  If you make links to this script as view,
# gvim, etc., then it will peek at the name used to call it and set options
# appropriately.
#
# Based on a script by Wout Mertens and suggestions from Laurent Bihanic.  This
# version is the fault of Benji Fisher, 16 May 2005 (with modifications by Nico
# Weber and Bjorn Winckler, Aug 13 2007).
# First, check "All the Usual Suspects" for the location of the Vim.app bundle.
# You can short-circuit this by setting the VIM_APP_DIR environment variable
# or by un-commenting and editing the following line:
# VIM_APP_DIR=/Applications
if [ -z "$VIM_APP_DIR" ]
then
myDir="`dirname "$0"`"
myAppDir="$myDir/../Applications"
for i in ~/Applications ~/Applications/vim $myDir $myDir/vim $myAppDir $myAppDir/vim /Applications /Applications/vim /Applications/Utilities /Applications/Utilities/vim; do
if [ -x "$i/MacVim.app" ]; then
VIM_APP_DIR="$i"
break
fi
done
fi
if [ -z "$VIM_APP_DIR" ]
then
echo "Sorry, cannot find MacVim.app.  Try setting the VIM_APP_DIR environment variable to the directory containing MacVim.app."
exit 1
fi
binary="$VIM_APP_DIR/MacVim.app/Contents/MacOS/Vim"
# Next, peek at the name used to invoke this script, and set options
# accordingly.
name="`basename "$0"`"
gui=
opts=
# GUI mode, implies forking
case "$name" in m*|g*|rm*|rg*) gui=true ;; esac
# Restricted mode
case "$name" in r*) opts="$opts -Z";; esac
# vimdiff, view, and ex mode
case "$name" in
*vimdiff)
opts="$opts -dO"
;;
*view)
opts="$opts -R"
;;
*ex)
opts="$opts -e"
;;
esac
# Last step:  fire up vim.
# The program should fork by default when started in GUI mode, but it does
# not; we work around this when this script is invoked as "gvim" or "rgview"
# etc., but not when it is invoked as "vim -g".
if [ "$gui" ]; then
# Note: this isn't perfect, because any error output goes to the
# terminal instead of the console log.
# But if you use open instead, you will need to fully qualify the
# path names for any filenames you specify, which is hard.
exec "$binary" -g $opts ${1:+"$@"}
else
exec "$binary" $opts ${1:+"$@"}
fi
For 'mark' (which starts up Marked) I have a link to executable file.  This requires the developer to install this in the app.

mark -> /Applications/Marked.app/Contents/Resources/mark



+1

You can avoid the sandboxing requirements by bundling the CLI script as a .pkg installation package; the preferable location to install the script (or binary if you go that route) would be /usr/local/bin.  The user wishing to have such a script would select an application menu item to launch the installer.

My own workaround has been to simply associate the relevant code files with the app, and run open filename

Hmm, are you sure this would work and is allowed by Apple? If the installer is launched from within Textastic, wouldn't it inherit its sandbox and thus prevent Authorization Services from working? From the docs: "Important: The authorization services API is not supported within an app sandbox because it allows privilege escalation." See https://developer.apple.com/library/mac/documentation/Security/Reference/authorization_ref/Reference/reference.html


Do you know a sandboxed app on the Mac App Store that includes an installation package?

+1

You would URL open the .pkg contained within your app bundle, this should hand off the file to the system-wide Installer.app which would perform the privilege escalation necessary for installation itself.  I haven't tested this within a sandboxed app myself.

Textwrangler has a CLI tool available as a download within the MAS version.
Along these lines can Textastic support an option like -w where the editor will wait until the tab with the file is closed so Textastic can be used to write a checkin message to git/mercurial/svn etc.?

I guess combining -n and -W would work:

-n, --new Open a new instance of the application even if one is already running.
-W, --wait-apps Blocks until the used applications are closed (even if they were already running).
-1

The only issue with this solution is that Textastic does not actually close when the tab is closed, only when the entire app is quit. This makes that particular workflow unsuitable for git commit messages or similar.

Actually, I guess since an entire new app instance is launched instead of opening in the same instance, we can just quit that instance with Cmd+Q instead of Cmd+W, and achieve the desired results., and not affect any other open documents.

+1

Would be great if file type and indentation settings could be passed as command line parameters as well.