Skip to content

Instantly share code, notes, and snippets.

@amake
Created June 2, 2016 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amake/cd3a9695cdef9a0da1f87e402950408e to your computer and use it in GitHub Desktop.
Save amake/cd3a9695cdef9a0da1f87e402950408e to your computer and use it in GitHub Desktop.
A Swift CLI tool for calling arbitrary OS X Services
//
// main.swift
// doservice
//
// Created by Aaron Madlon-Kay on 6/2/16.
// Copyright © 2016 Aaron Madlon-Kay. All rights reserved.
//
import Foundation
import AppKit
let args = NSProcessInfo.processInfo().arguments
guard args.count == 4 else {
print("Usage: doservice <service name> <data type> <argument>")
print("Example: doservice \"New Terminal at Folder\" public.file-url /foo/bar")
exit(1)
}
let pb = NSPasteboard.pasteboardWithUniqueName()
pb.setString(args[3], forType: args[2])
NSPerformService(args[1], pb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment