Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I run the following commands for logkext a lot in my terminal and would like a know a way to automate the whole process.

  1. Open terminal
  2. type "sudo logKextClient"
  3. Type in administrator password
  4. logKextClient has its own password which I need to type now
  5. logKextClient is running now. prompt is logKextClient >
  6. I have to type a command here. "open"
  7. Then I need to close a window that opens. Window is titled out_logFile.txt. Usually it opens in TextEdit. I don't mind force quitting it. As a copy of the file is saved on the desktop.

I'd like to be able to double click something and execute the above list of commands/actions flawlessly.

Many thanks for your suggestions.

share|improve this question

You can use Automator to do this. The instructions are for Mavericks, but the main part is the same in all OSs.

  1. Open Automator
  2. Click "New Document"
  3. Select "Workflow"
  4. Click "Record" (it may ask you to grant permission, click "Open System Preferences")
  5. Perform all of the actions you want it to do
  6. Click the stop button
  7. Save the workflow

Now, when you want it to perform those actions, simply open the workflow.

share|improve this answer
Cool. I'll try it and get back to you in a minute. Meanwhile, will the saved automator file work on another computer? I sometimes work on my macbook on the road and the passwords can be different. – Freckles Jan 13 '14 at 3:28
@Freckles if your user password to authenticate for sudo privileges is different, you will need to re-record the workflow, as Automator is performing exactly what you tell it to do. For example, if you type hghghghhg as your password and run the workflow on another computer, Terminal will say "password incorrect" because Automator typed in hghghghhg. – Rajiv Jan 13 '14 at 3:31
@CompuKid.. Automator doesn't do what I desire or rather is not the suitable solution. The position of my desktop can be different at any given time of the day and "watch me do" fails. I'll explore automator and see what I can do. Otherwise, maybe a shell script should work? – Freckles Jan 13 '14 at 3:43
In addition to the answer above - if you want to automate anything with passwords (what you usually should not!) you might want to use expect. You can get it with homebrew or the other package managers. – bdecaf Jan 13 '14 at 9:00
@Freckles yes, I think a shell script would work better. I didn't see that option. – Rajiv Jan 13 '14 at 21:02

I suggests using AppleScript. I am not able to provide the actual code, only some idea.

a) Launch Terminal:

b) Telling Terminal to execute command:

c) Giving Terminal super user privilege:

I'm not sure if (b) and (c) can blend perfectly.

d) Close Text Edit window/document:

share|improve this answer

I went through the exact same process back when I was playing around with logKext. The unix command you may want to explore is /usr/bin/expect.

It can get complex quickly, but basically what it does is act as a mediator between you and the programs you're running so it can provide answers that you would normally have to type. As an example, I built this script so I could automate the process of printing the logKext output. You should recognize all of the commands you'd normally type to logkextClient yourself...

#!/usr/bin/expect -f
spawn logkextClient
expect "logKext Password:"
send "mylogkextpassword\r"
expect "logKextClient > "
send "print\r"
expect "logKextClient > "
send "quit\r"

Back in 10.5 and 10.6 this worked well for me for outputting the logKext print so I could pipe it into an email and send it. However, I was running this logged in as root to terminal, so it was simple.

Theoretically, if you weren't logged in as root, you could instead say

#!/usr/bin/expect -f
spawn sudo -k logkextClient
expect "Password:"
send “myrootpassword\r”
expect "logKext Password:"
send "mylogkextpassword\r"
expect "logKextClient > "
send "print\r"
expect "logKextClient > "
send "quit\r"

(note that I used sudo -k intentionally to be consistent and require a password every time)

So you could use your favorite command line editor to create this script, do a chmod +x to it and drag it to the dock for launching... Theoretically.

But I have been having problems in Mavericks getting /usr/bin/expect to behave properly with sudo, so this isn't working for me in other scripts like it should. And I don't have logKext installed at all anymore for testing anyway.

But I think this is the direction you may want to head.

Good luck!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.