Category 'SwiftShell'

SwiftShell 3

28 May 2017

SwiftShell 3 is finally out of beta, with a much improved readme.

So much so it may even be too long now.

Combine markdown files and convert to HTML in a Swift script.

15 May 2016

Swift 3

Sam Burnstone recently wrote about how to convert a simple shell script to Swift. Here’s the same shell script rewritten using SwiftShell and FileSmith.

Move files to the trash with a Swift script

12 Apr 2016

Swift 3

I really don’t like using the ‘rm’ shell command – one misplaced character and you can do some serious damage. But when working in the Finder I don’t think twice about deleting files, because I know I can always get them back from the trash. So here is a Swift shell script which does exactly that – it moves files to the trash instead of deleting them permanently.

The syntax is very simple – all parameters refer to file system items which should be moved to the trash:

trash file.txt a_folder
trash *.m *.h

SwiftShell 2.0 Readme

12 Nov 2015

I finally got around to updating the SwiftShell 2.0 readme with some actual usage instructions:

SwiftShell: An OS X Framework for command line scripting in Swift.

How to use Swift for shell scripting

17 Sep 2015

To be honest I’m not very good at shell scripting. It’s very useful for automation so I would like to be, but I just don’t like the syntax. For instance, this is how you check if a variable is greater than 100:


if [ $var -gt 100 ]
    <do some stuff>

Redesigning an API - Swift 2.0 style

02 Sep 2015

SwiftShell (an OS X framework for shell scripting in Swift) is currently using the > operator to combine shell commands, streams and functions, and » to print the results:
// SwiftShell 1

run("echo piped to the next command") |> run("wc -w") |>> standardoutput

// print out line number and content of each line in standard input
var i = 1
standardinput.lines() |> map {line in "line \(i++): \(line)\n"} |>> standardoutput

But Swift 2.0 is here, and it’s clear the way forward is protocols, method chaining and error handling. And being more explicit about what is going on. So for SwiftShell 2 I’m planning something like this: