0

Now I am working on mac osx app development. I need to check if os is up to date or outdated programmatically. I can see it via Software Update of System Preferences. There are a lot of solutions to get current mac os version. But I am not interested in version. Only interested in if os is the latest one or old one.

enter image description here

But I want to know it in my app programmatically. swift code or objective-c code is fine.

6
  • 2
    In the shell run softwareupdate --list and parse the result. Commented Jan 28, 2020 at 11:30
  • Yes, it is. But you are able to read data asynchronously from the shell with NSTask. Commented Jan 28, 2020 at 16:37
  • @vadian softwareupdate --list is helpful for me As you know, this shell command is async $ softwareupdate --list Software Update Tool Finding available software No new software available. what I want to get as result is the messages under "Finding available software". import SwiftShell do { let command = runAsync("softwareupdate", "--list") try command.finish() let result = command.stdout.read() print(result) } catch { } then the result is below Software Update Tool Finding available software I can not get "No new software available" Commented Jan 28, 2020 at 16:43
  • @vadian Could you provide me the code snippet getting full results of "softwareupdate --list"? Commented Jan 28, 2020 at 16:46
  • Please look at the Ray Wenderlich Tutorial Commented Jan 28, 2020 at 17:03

1 Answer 1

1

Below is simple code snippet but I spent a lot of time to get it done. I hope someone does not waste time like me.

import SwiftShell

func getIsOSXUpdate() -> Bool {
    // softwareupdate --list|tee
    let command = runAsync("softwareupdate", "--list")
    do {
        try command.finish()
    } catch {
        NSLog("could not collect available updates.")
        return false
    }

    let result = command.stdout.read()
    let error = command.stderror.read()

    if error.contains("No new software available") {
        return true
    }
    return false
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.