【问题标题】:Making a terminal executable file that changes the date on your Mac [closed]制作一个可以更改 Mac 上日期的终端可执行文件 [关闭]
【发布时间】:2020-11-27 15:26:32
【问题描述】:

如果我们去SystemPreferences > date and time,我们可以更改我们mac的日期。你能创建一个终端可执行程序来更改我打开它的日期吗?

【问题讨论】:

    标签: bash macos terminal zsh


    【解决方案1】:

    您可以在终端使用以下命令更改 mac 的日期。

    date -u {month}{day}{hour}{minute}{year}
    

    用两位数替换括号。要设置,2020 年 10 月 16 日 21:16 将变为以下命令:

    date 1016211620
    

    或者你可以创建苹果脚本来做到这一点:

    set ntpdPID to do shell script "systemsetup -getusingnetworktime; exit 0" with administrator privileges
    if ntpdPID is "Network Time: On" then
        do shell script "systemsetup -setusingnetworktime off" with administrator privileges
        do shell script "systemsetup -setdate '01:24:1984' -settime '03:00:00'" with administrator privileges
    else
        do shell script "systemsetup -setusingnetworktime on" with administrator privileges
    end if
    

    要创建苹果脚本,请参阅reference

    【讨论】:

    • 是否有终端命令可以将日期设置为“今天”?
    • sudo sntp -sS time.apple.com 会将日期和时间设置为当前日期和时间。
    猜你喜欢
    • 2015-06-05
    • 1970-01-01
    • 1970-01-01
    • 2019-09-15
    • 2015-10-09
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多