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

相关推荐
pe7er2 天前
macOS 应用无法打开(权限问题)解决方案
macos·mac
harmful_sheep4 天前
mac生效的终端查看
macos
iOS门童5 天前
macOS 应用"已损坏"无法打开?一文搞懂 Gatekeeper 与解决方案
macos
NPE~5 天前
[工具分享]Maccy —— 优雅的 macOS 剪贴板历史管理工具
macos·教程·工具·实用工具
差不多程序员5 天前
Mac安装OpenClaw-cn保姆级教程
macos
dzl843945 天前
mac 安装python
开发语言·python·macos
Bruce_Liuxiaowei5 天前
在 macOS 上通过 Docker 本地安装 OpenClaw 完整教程
macos·docker·容器·openclaw
阿捏利5 天前
详解Mach-O(十五)Mach-O __DATA_CONST
macos·ios·c/c++·mach-o
ShikiSuen5 天前
macOS 的 CpLk 中英切换卡顿的元凶在 InputMethodKit 本身
macos
xiayutian_c5 天前
如虎添翼-MacOS
macos