Skip to content

Instantly share code, notes, and snippets.

<?xml version="1.0" ?>
<!--
This sample schedules a task to start about 10 seconds after the task is deployed.
-->
<Task>
<Triggers>
<TimeTrigger>
<Enabled>true</Enabled>
<Delay>PT10S</Delay>
</TimeTrigger>
@zepedebo
zepedebo / simpleFileCount.swift
Created January 3, 2017 22:51
Simple file count
let fm = try FileManager.default.contentsOfDirectory(atPath: "./")
print(fm.count)
@zepedebo
zepedebo / fileCountWithPipes.swift
Created December 31, 2016 01:48
Counting files in a directory with swift and external processes
// Set up the ls process
let lsProc = Process()
let lsStdout = Pipe()
lsProc.launchPath = "/bin/ls"
lsProc.standardOutput = lsStdout
// set up the wc process
let wcProc = Process()
let wcStdout = Pipe()
wcProc.launchPath = "/usr/bin/wc"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>_SPCommandLineArguments</key>
<array>
<string>/usr/sbin/system_profiler</string>
<string>-nospawn</string>
<string>-xml</string>
public func getItemsFromSystemProfiler(dataTypeString: String) -> [[String:AnyObject]]? {
let task = Process()
let pipe = Pipe()
// Set up our task process
task.launchPath = "/usr/sbin/system_profiler"
task.arguments = ["-xml", dataTypeString]
task.standardOutput = pipe
// Go!
let hwinfo = launchAndGetText(path:"/usr/sbin/system_profiler",
args: ["SPHardwareDataType"])
let lines = hwinfo.components(separatedBy: "\n")
var uuid: String = ""
for line in lines {
let parts = line.components(separatedBy: ":")
if parts.count > 1 && parts[0].contains("Hardware UUID") {
uuid = parts[1].trimmingCharacters(in: CharacterSet.whitespaces)
public func launchAndGetText(path: String, args: [String]) -> String {
let ps = Process()
ps.launchPath = path
ps.arguments = args
let psStdOut = Pipe()
ps.standardOutput = psStdOut
ps.launch()
ps.waitUntilExit()
let spProc = Process()
spProc.launchPath = "/usr/sbin/system_profiler"
spProc.arguments = ["SPHardwareDataType"]
spProc.launch()
spProc.waitUntilExit()
do {
var coyote = Predator()
var roadrunner = Prey()
coyote.attach(device:"rocket", location: "back")
coyote.attach(device:"roller skates", location: "feet")
coyote.attach(device:"helmet", location: "head")
try coyote.navigate(feature: "Sharp Turn")