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.测试运行,以分钟为单位,确定后开始执行

相关推荐
踏着七彩祥云的小丑1 天前
Mac——已安装工具查找
macos
小红的布丁1 天前
公网 IP、私网 IP、路由表、转发表与 MAC 地址的关系
tcp/ip·macos·智能路由器
Lecxcy_Kastreain1 天前
如何自适应 MacOS
macos
简单点了1 天前
mac安装node环境
macos
简单点了1 天前
mac安装vm装win11虚拟机
macos
todoitbo1 天前
装了 QClaw 之后,我卸掉了好几个 Mac 软件
人工智能·macos·ai·软件·openclaw·qclaw
總鑽風2 天前
搭建Spring Boot + ELK日志平台,实现可视化日志监控
spring boot·elk·macos
CS创新实验室2 天前
《计算机网络》深入学:IP地址 VS. MAC地址
tcp/ip·计算机网络·macos
是孑然呀2 天前
mac m4mini安装软件
macos
简单点了2 天前
mac安装Java环境
java·macos