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 天前
第 3 篇:IDEA 最新版下载与完整安装教程(Mac)
java·macos·intellij-idea·idea
CodeClimb3 天前
Mac 磁盘无法推出(DMG外接盘)排查处理教程
macos
Karl_fang3 天前
🥳 再也不用拿起手机抄验证码!我做了一个 Android → Mac 的「验证码接力」工具
前端·macos·ai编程
csdn_aspnet5 天前
macOS 10 、Docker 玩轉 MySQL
运维·mysql·macos·docker·容器·mac
秋雨梧桐叶落莳5 天前
【iOS】Block底层详解
macos·ios·cocoa
高调的涵涵7 天前
café 和 café 不是一个文件名
macos
独隅9 天前
WebStorm macOS 安装部署与高效调优完全指南
ide·macos·webstorm
独隅9 天前
WebStorm macOS 安装调优与实战效能全景
ide·macos·webstorm
2601_967987379 天前
安装 Redis 或 Redis Stack
linux·windows·redis·macos·安装
高调的涵涵9 天前
1GB 文件,df 说没占地方
macos