MacOS Tahoe26.1自制定时休眠app

1.打开自动操作

2.文稿类型选择应用程序

3.接着选择实用工具-运行AppleScript

4.替换默认代码

Swift 复制代码
on run
	-- 弹出输入框
	set theMinutes to text returned of (display dialog "请输入多少分钟后让 Mac 进入睡眠:" default answer "30" buttons {"取消", "确定"} default button "确定" cancel button "取消" with title "定时休眠")
	
	-- 检查是否取消
	if theMinutes is "" then return
	
	-- 转换为秒
	set secondsToWait to theMinutes * 60
	
	-- 使用 do shell script 并允许自动认证(避免手动输入密码)
	do shell script "sleep " & secondsToWait & " && pmset sleepnow" user name "your_username" password "your_password" with administrator privileges
	
end run

替换 your_username 为你的帐户名, your_password为你的登录密码

5.保存及修改图标

6.测试运行,以分钟为单位,确定后开始执行

相关推荐
望眼欲穿的程序猿18 分钟前
基于Linux&MacOS 开发Ai8051U
linux·运维·macos
TESmart碲视44 分钟前
M4芯片MacBook支持多显示器吗?mac如何与KVM切换器使用。
macos·计算机外设·mst·kvm切换器·双屏kvm切换器
我的golang之路果然有问题1 小时前
Mac 上的 Vue 安装和配置记录
前端·javascript·vue.js·笔记·macos
青州从事52117 小时前
20260108【mac】【brew】【docker】安装
macos·docker·eureka
centor1 天前
国际版 UnitySetup-Android-Support 安装 Mac 设备
android·macos
旭日跑马踏云飞1 天前
【Mac】实用技巧-在新窗口中打开当前文件夹
macos
林疏safe1 天前
CAD2026最新mac的安装教程收集免费分享
macos
Digitally1 天前
如何高效安全地将 iPhone 与 Mac 同步
安全·macos·iphone
程序员允诺1 天前
办公 WiFi 二次隔离下的远程桌面解决方案实践(Mac → Win11)
macos
hudawei9961 天前
win和Mac在创建python虚拟环境,启动环境等操作的异同
windows·python·macos·虚拟环境