Getting the popupbuttons’ values as Var and send to a shell script as variable params

Hello everyone. I am very new to swift coding and I have a question below.   Hope to find some helps here. Thank you very much!

 

 

My xcode version is 10 and I am using MacOS 10.13.6.

 

 

I am using 3 popupbuttons to select 3 Corporate App versions to write to a location with a shell script. I want the 3 App versions to be variable as can be selected from the popupbuttons menus. The 3 popupbuttons menus are all numbers from 1 to 9.

 

 

My code in the ViewController.swift as follow. How should I catch the variables selected from the 3 popupbutton menus and pass them to the shell script as variable params? Thank you.

 

 

The line ” let arguments = [“/WriteAppToShare/WriteAppToShare.sh”,”varAppVer1″,”varAppVer2″,”varAppVer3″ ” will be run as /WriteAppToShare/WriteAppToShare.sh varOSVer1 varOSVer2 varOSVer3.

I am expecting it to be run as /WriteAppToShare/WriteAppToShare.sh 2 6 8 if I select 2 6 8 from the 3 corresponding popup buttons.

 

 

 

 

=====Code=========================

 

 

    @IBOutlet weak var AppVer1: NSPopUpButton!

 

    @IBOutlet weak var AppVer2: NSPopUpButton!

 

    @IBOutlet weak var AppVer3: NSPopUpButton!

 

 

    @IBAction func WritingAppNo1No2No3(_ sender: NSButton) {

        let varAppVer1 = AppVer1no.selectedItem?.accessibilityAllowedValues()

        let varAppVer2 = AppVer2no.selectedItem?.accessibilityAllowedValues()

        let varAppVer3 = AppVer3no.selectedItem?.accessibilityAllowedValues()

   

        let path = “/bin/bash”

 

        // let arguments = [“/WriteAppToShare/WriteAppToShare.sh”,”2″,”6″,”8″]

        // The above line of code works if I just write the number 2 6 8 directly. The 2 6 8 are the params to pass to the shell script. But I want these 3 values to be variables by selected them from the popupbuttons.

   

        let arguments = [“/WriteAppToShare/WriteAppToShare.sh”,”varOSVer1″,”varOSVer2″,”varOSVer3″

 

        // The above line does not work.

        // It will be run and output as /WriteAppToShare/WriteAppToShare.sh varOSVer1 varOSVer2 varOSVer3.

        // I am expecting it to be run and output as /WriteAppToShare/WriteAppToShare.sh 2 6 8 if I select 2 6 8 from the 3 corresponding popup buttons.

 

 

 

 

        sender.isEnabled = false

        let task = Process.launchedProcess(launchPath: path, arguments: arguments)

        task.waitUntilExit()

        sender.isEnabled = true

   

    }

 

 

 

 

 

=====Code=========================

Powered by WPeMatico

You may also like...

Comments are closed.