1

hoping someone can help with this. I am trying to write an automator terminal script in Mac OS Catalina that will turn off WiFi, turn off automatic date and time settings, and set my mac to a specific system date and time. I have really no programming experience but what I have so far works to turn off wifi and change the system date and time...but the script will not exit in automator...it just keeps spinning. Not sure how to get the Sudo -S command to exit once it sets the system date and time. Here's what I have so far:

networksetup -setairportpower en0 off

echo "password" | sudo -S date 0101000120

So this will turn off wifi, and will pass my password (can also do it through a dialog but thats not my problem) and will set the system date...then the automator wheel just spins....

  1. Any ideas how to get the terminal script to exit and move on to the next command...or should I just run it and then quit the script as its spinning which isn't ideal but also works
  2. command to turn on and off auto updating of mac system date and time?

Thanks so much for reading and greatly appreciate any help.

EDIT: Currently re-wrote the automator task to run the terminal command, ask for a password then pass that on:

networksetup -setairportpower en0 off pw="$(osascript -e 'Tell application "System Events" to display dialog "Password:" default answer "" with hidden answer' -e 'text returned of result' 2>/dev/null)" && / echo "$pw" | sudo -S date 0101000120

Still spins the wheel in an infinite loop at the end but I can click it and force stop. Anyone knows a way to just get it to stop appreciate it!

  • echo sends output to the console. A password prompt is expecting input. The command you’re looking for is expect. However, turning off WiFi and changing the system time is a rather odd workflow. What are you trying to accomplish? – Allan Mar 29 at 22:35
  • I run a legacy program from a now defunct company that configures old but very reliable equipment where I work (unfortunately no software updates for a 1998 windows program). It will not run if system date in parallels is past a certain date. Its just a pain to manually go in though the mac and change all this stuff manually so trying to automate it...mostly so I don't have to be the only one able to boot this up! – rhk118 Mar 29 at 22:43
  • the echo prompt is sending my password to the terminal and accepting it...the following sudo -s command runs but then AppleScript just spins...tried 'expect' instead of 'echo' but now asking for "expected input again" which echo seemed to be providing. Everything I've written works OK, just won't end or exit past the date...is echo doing that? – rhk118 Mar 29 at 22:47
  • Sorry, but I'm having a tough time following. You refer to a Applescript, but I'm not seeing where you call/reference it. Also, can't you just set the date on the VM itself instead of on the host? – Allan Mar 29 at 23:41
  • Thanks Allan. AppleScript may be the wrong terminology. I am using a terminal command from within the Automator application. If you copy and paste what I have for code in original post you will see how it works (just substitute your system password where I have "password")...then it hangs. I think the problem is I don't know how to exit the sudo -s command and it seems stuck in a loop. – rhk118 Mar 29 at 23:58
1

I could get this to work by piping the password to sudo from a file instead of using echo:

sudo -S date 0101000120 < ~/passwd.txt

I'm not sure what security implications this has though, but it feels wrong ...

If you're after a quick and dirty solution then this will do it, however as per nohillside's comment, here are some instructions to run sudo commands without requiring a password. These suggestions work for me on Mojave in iTerm2 and terminal.

| improve this answer | |
  • 1
    It has about the same implications as the version in the question: anybody who has access to passwd.txt (or to the Automator file for the approach taken in the question) can log in as Administrator afterwards. Might be better to use visudo to edit the sudoers file and allow password-less sudo access to the date command for the specific user. – nohillside Mar 30 at 11:12
  • OK thanks. I don't feel comfortable either having the PW in a file like that, and when I tried it works as well but automator just spins the wheel in an infinite loop. So I have modified for it to ask for password then pass this to the Sudo -S command...then will just have to click the "exit" button to get automator to stop spinning. Still faster than going into preferences and changing all of this. – rhk118 Mar 30 at 19:13
  • networksetup -setairportpower en0 off pw="$(osascript -e 'Tell application "System Events" to display dialog "Password:" default answer "password" with hidden answer' -e 'text returned of result' 2>/dev/null)" && / echo "$pw" | sudo -S date 0101000120 – rhk118 Mar 30 at 19:13
  • Anyone know a simple way to turn off autoupdating of date and time? What I've found is parallels is really good at finding the date and time and passing it onto windows even if you de-select it...once that happens the windows program freezes... – rhk118 Mar 30 at 19:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .