How to change timezone instantaneously?

I can use mouse clicks and keystrokes automation but I need the automation of changing timezone to be as fast as possible. Is apple script an answer? If yes, I can't write apple script.

What I am looking for?

  1. The automation would be triggerd manually.
  2. The automation would change my Mac's timezone to the specified timezone.
  3. Great if I don't need to put in my password each time I have to change the timezone.

It appears to can set it using the command:

sudo /usr/sbin/systemsetup -settimezone "name"

You can list them with -listtimezones and get with -gettimezone.

The command must be run with administrator privs, but you could add the command to your sudoers file, which I think would be relatively safe if you fully supply the command.

2 Likes

The one that works is this (For london timezone):

echo 'your_password' | sudo -S systemsetup -settimezone Europe/London

Your code gave error. I put your code in chatgpt. And it corrected it. I tested and it works. [When you are typing the password, which is the password with which you have locked your laptop, do not put your password inside single inverted comma]

Assuming you'll be triggering the macro manually, you can prompt for the password and reference a variable in the script:

Local__Password="$KMVAR_Local__Password"
echo "$Local__Password" | sudo -S systemsetup -settimezone Europe/London

1 Like

My code was copied verbatim from a Terminal window with the only change being the timezone name.

I strongly recommend against putting your admin password in clear text in a macro.

This is why I suggested a password prompt.

oh did you mention this in your last response?

I did not understand this line. I already have administrative priviledges (i.e. I am the admin). What are sudoers? How to fully supply command?

Why do you think it is not safe? I mean a person has to be physically able to access my laptop in order to use the password, right?

Indirectly, yes, I suggested putting it in the sudoers file which allows specific commands to be run with admin permissions without requiring a password.

See:

https://help.ubuntu.com/community/Sudoers

That's for Ubuntu, but it covers the idea.

Any software running on your Mac could potentially access it (well, in theory, sandboxed software could not but in practice, who knows). Passwords should be at the least stored in the Keychain which you could do using the Set Keychain Password to Text and Set Variable to Keychain Password actions and the technique @noisneil suggested.

But I prefer using sudoers because it removes having to store your password anywhere, and it's not much of a security risk to allow anything to change your timezone.

1 Like