program with terminal

defaults write com.apple.mail DisableInlineAttachmentViewing -bool yesHey Guys,


I wanted to program something for a Guy with no simple idea, what he can do with his Mac.


In this program should the Terminal open and than should automaticaly paste the sentence


" defaults write com.apple.mail DisableInlineAttachmentViewing -bool yes " (its for Mail)


This comand shout perfom.


Until this the Terminal should close.


The Question is: How can I do it?


Thanks!


Wusta

To launch Terminal from your app:

https://stackoverflow.com/questions/27505022/open-another-mac-app


let url = NSURL(fileURLWithPath: "/System/Applications/Utilities/Terminal.app", isDirectory: true) as URL

let path = "/bin"
let configuration = NSWorkspace.OpenConfiguration()
configuration.arguments = [path]
NSWorkspace.shared.openApplication(at: url,
  configuration: configuration,
  completionHandler: nil)


Look here to see how to open Terminal with a predefined command

https://stackoverflow.com/questions/31192722/run-a-terminal-command-in-a-mac-app-with-swift-xcode

Thanks!


The Thing is, I copied the phrase from the other User. It´s clear, that he doesn´t use my textline.


He posted this:


let task = NSTask()
task.launchPath = "/usr/sbin/sysctl"
task.arguments = ["-w", "net.inet.tcp.delayed_ack=0"]
let pipe = NSPipe()
task.standardOutput = pipe
task.standardError = pipe
task.launch()
task.waitUntilExit()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output: String = NSString(data: data, encoding: NSUTF8StringEncoding) as! String


for the line "

sudo sysctl -w net.inet.tcp.delayed_ack=0"


But in my line is there no User.

I tried to use "task.arguments", but it doesnt work.


Can you help me by this Situation?

let task = NSTask()
task.launchPath = "/usr/sbin/sysctl"
task.arguments = ["-w", "net.inet.tcp.delayed_ack=0"]
let pipe = NSPipe()
task.standardOutput = pipe
task.standardError = pipe
task.launch()
task.waitUntilExit()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output: String = NSString(data: data, encoding: NSUTF8StringEncoding) as! String



You wrote:

But in my line is there no User.


Which line ?

" defaults write com.apple.mail DisableInlineAttachmentViewing -bool yes " (its for Mail)

what you want to do is write a program which sets a default, for a user who is not comfortable with the command line.

You could make an objective C app which does this


NSUserDefaults * defaults = [[NSUserDefaults alloc] initWithSuiteName:@"com.apple.mail"];

if (defaults) {

[defaults setObject:@YES forKey:@DisableInlineAttachmentViewiing];

}


the above is entirely untested, by the way.


if won't open Terminal, but it could display a window saying "Mail will no longer show attachments inline" instead. For extra points you could give it a UI and enable your user to turn the preference on or off with a button in a window.


Note that stomping on the preferences of other applications is not a great way to interact with those applications.

Thanks for your help.


I know, that´s normally not the best way.

Perhaps I´m to stupid to change it in the normal preferences. But I didn´t see it in google how to change it.

program with terminal
 
 
Q