So my code so far looks like this:
import Foundation
import AppKit
print("Starting")
let base = NSWorkspace()
print("Launching Terminal")
base.launchApplication("Terminal") //launches terminal
print("Terminating terminal")
let apps = base.runningApplications
for app in apps {
if app.localizedName == "Terminal" {
print(app.localizedName)
app.terminate() //Terminate
break
}
}
I have figured out how to start terminal and then how to close it, but I don't know how to pass it a command. The command I want to pass it is: "screencapture ~/Desktop/screenshot.jpg"