How to run zsh commands from Xcode

I am trying to make an application for Mac OS that changes a user password from the terminal. I am using z-shell and am new to developing for Mac and it is my first time using Xcode.


I am wondering if it is possible to run z shell commands from an xcode application, and if so then how? Any help would be appreciated.


edit: explained a little more in a later reply

Replies

If you are looking to open a Terminal from within Xcode, search for "Open Terminal window within Xcode" on the internet. There are a couple of ways of doing, but, it all boils down to writing a script file to open the Terminal.app using "open", and linking a new custom behavior to run the script from either a key combination or from the "Behaviors" menu.


If this is not the case, it's not clear what you want to do.

Hi,


Thank you for the reply! I'm sorry I wasn't very clear with my concern..


I wrote a short shell script that changes the password of the account that the user chooses using the passwd command. I wanted to make some sort of clean and nice gui for it, but couldn't really find anything that would help me build a nice gui, and someone recommended that I try to make an xcode app for it.


I was hoping that I could use xcode to make a simple app that just basically takes the user's input for which user account's password they want to change, the old password, and new password and then does it for them.. if that makes more sense?

I wrote a short shell script that changes the password of the account that the user chooses using the passwd command. I wanted to make some sort of clean and nice gui for it

Running the

passwd
command from a GUI app is tricky because that command expects to have
stdin
connected to a terminal device. You can do this, using a pseudoterminal, but it’s a challenge.

A better option would be to use an API to change the user’s password, and the preferred API for this is the OpenDirectory framework. This isn’t easy, but it’s a lot easier than messing with pseudoterminals.

There’s two parts to this:

  1. Tracking down the user’s OD record

  2. Changing the password in that record

Part 1 is the hard part, but you can find some code to do it in this post.

Note That code uses

kODNodeTypeLocalNodes
, which means it’ll only operate on local users. If you want to support any user, including users from a remote directory service, use
kODNodeTypeAuthentication
.

Part 2 is surprisingly easy. Once you have the OD record, you can just call

changePassword(_:toPassword:)
.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thank you very much, I will try this 🙂