Xcode - Using a shell script with swift 3

Discussion in 'Mac Programming' started by Miles.Kelly97, Jul 25, 2017.

  1. Miles.Kelly97 macrumors newbie

    Joined:
    Nov 24, 2015
    Location:
    Tunbridge Wells
    #1
    Hi guys,

    I was wondering if I could have a bit of help with this. I am trying to create a Status bar app that will run a Shell script when a button is pressed but I am not sure how to do this.

    The command is "defaults write com.apple.finder CreateDesktop -bool FALSE;killall Finder" It hides the desktop.

    Could anyone give me any advance as to how to get a button pressed to action that command?

    Thanks Miles
     
  2. maculateConception macrumors 6502

    maculateConception

    Joined:
    May 28, 2017
    Location:
    Die Bundesstaat Kalifornien
    #2
    Something like this (found this on StackOverflow)

    Code:
    import Foundation
    
    @discardableResult
    func shell(_ args: String...) -> Int32 {
        let task = Process()
        task.launchPath = "/usr/bin/env"
        task.arguments = args
        task.launch()
        task.waitUntilExit()
        return task.terminationStatus
    }
    
    shell("ls")
    shell("xcodebuild", "-workspace", "myApp.xcworkspace")
    Note - I haven't tried anything like this. Just what I found online.

    https://stackoverflow.com/questions...inal-command-in-a-swift-script-e-g-xcodebuild
     

Share This Page