网站首页 > 博客文章 正文
苹果笔记本上装了一大堆各种应用,很多应用比较少用,使用spotlight进行查找时,又因为不记得应用的名字,只好在一大堆图标中仔细辨识;
一个比较好的方法就是给应用程序加上备注,这样能通过spotlight查找到,但是这种繁琐的事情怎么不让AI来帮忙,所以开始呼唤ChatGPT了。
第一步:让ChatGPT给我写个脚本,帮忙把已经安装的应用名字全导出到一个文件
Prompt提示词这么写:
请用AppleScript编写一个脚本,这个脚本的功能是从我的Application目录下把所有已经
安装的应用,读取应用的路径,名称和备注属性,按照“路径|名称|备注”的格式生成一个文本文件
ChatGPT很快就给出了一个AppleScript的代码例子,自己再人工稍微调整了一下:
-- 指定输出文件的路径
set outputPath to (path to desktop as text) & "applications.txt"
-- 获取 "/Applications" 文件夹中的所有应用程序
set appFolder to POSIX path of (path to applications folder)
set appList to list folder appFolder without invisibles
-- 打开输出文件以写入应用程序信息
set outputFile to open for access outputPath with write permission
-- 遍历应用程序并提取名称和 "Comments" 属性
repeat with appName in appList
set appPath to (appFolder & appName) as text
-- 使用 mdls 命令检查是否是应用程序
set isApplication to (do shell script "[ -d " & quoted form of appPath & " ] && mdls -name kMDItemContentTypeTree -raw " & quoted form of appPath & " | grep -q 'com.apple.application' && echo 'true' || echo 'false'") is "true"
-- 获取应用程序名称
-- set appNameText to name of (info for appPath)
-- 获取应用程序 "Comments" 属性
if isApplication then
try
set appNameText to (do shell script "mdls -name kMDItemDisplayName -raw -nullMarker '' -nokids -nobanner -nolocal " & quoted form of appPath)
on error
set appNameText to ""
end try
-- 获取应用程序 "Comments" 属性
try
set comments to (do shell script "mdls -name kMDItemFinderComment -raw -nullMarker '' -nokids -nobanner -nolocal " & quoted form of appPath)
on error
set comments to ""
end try
-- 将应用程序名称和 "Comments" 写入输出文件
write (appPath & "|" & appNameText & "|" & comments & linefeed) to outputFile as ?class utf8?
end if
end repeat
-- 关闭输出文件
close access outputFile
-- 显示完成消息
display dialog "应用程序信息已写入 " & outputPath
将代码复制到系统自带的脚本编辑器(Script Editor),运行后就能在桌面生成一个applications.txt文件,里面已经存放了所有在application目录下安装的应用信息;
application.txt部分内容:
/Applications/Spark.app|Spark|
/Applications/Postgres.app|Postgres|
/Applications/HelloFont.app|HelloFont|
/Applications/VOX.app|VOX|
/Applications/Serviio-Console.app|Serviio-Console|
/Applications/SourceTree.app|SourceTree|
/Applications/LimeChat.app|LimeChat|
/Applications/Text Scanner.app|Text Scanner|
/Applications/ProtoPie.app|ProtoPie|
/Applications/CapCut.app|CapCut|
/Applications/Altair GraphQL Client.app|Altair GraphQL Client|
/Applications/百度翻译.app|百度翻译|
...
第二步:让ChatGPT帮忙整理出每个应用的简介
这一步让ChatGPT自动根据提供的应用名称来总结应用的简介和分类;
提示词:
接下来上传的内容,每一行的格式为“路径|应用|备注”,请用一句话生成应用的分类描述,
并写入每行的备注字段,以excel格式输出
然后把第一步得到的application.txt内容贴到对话,ChatGPT很快就给出了分析后的内容
这里可以根据自己的需要调整提示词(Prompt) ,让他给出你喜欢的描述方式
将生成的内容复制到文件application_update.txt保存;
第三步:让ChatGPT再写个脚本,把应用的简介写到每个应用到备注里
这一步和第一步一样,让chatGPT来帮助写脚本,把更新后的application_update.txt内容分别写到每个应用的备注项中。
请使用applescript开发一个脚本,这个脚本功能是从"application_update.txt"文件中读取内容,内容格式为“apppath|app|comment”的列表,
脚本需要依次读取apppath和comment,根据apppath指定的应用,更新这个应用的kMDItemFinderComment属性为comment的内容
同样,chatgpt给出的脚本,经过我调整一下后,直接贴到脚本编辑器(Script Editor)中运行
-- 请将以下路径替换为你的文本文件路径
set filePath to (path to desktop as text) & "applications_updated.txt"
try
-- 打开文本文件并按行读取内容
set fileContents to read file filePath as ?class utf8?
-- 将文本文件内容分割成行
set textItems to paragraphs of fileContents
-- 循环遍历每行内容
repeat with lineText in textItems
try
-- 使用管道符分割应用路径和注释
set AppleScript's text item delimiters to "|"
set lineItems to text items of lineText
set appPath to item 1 of lineItems
set commentText to item 2 of lineItems
-- 创建 AppleScript 代码来设置应用程序的 kMDItemFinderComment 属性
set pathCommentScript to "set filepath to (POSIX file \"" & appPath & "\" as alias)"
set setCommentScript to "tell application \"Finder\" to set comment of filepath to \"" & commentText & "\""
-- 运行 AppleScript 代码
do shell script "osascript -e " & quoted form of pathCommentScript & " -e " & quoted form of setCommentScript
-- 使用 xattr 命令来设置应用程序的注释属性
--do shell script "xattr -w com.apple.metadata:kMDItemFinderComment " & quoted form of commentText & " " & quoted form of appPath with administrator privileges
on error errMsg
display dialog "设置注释属性失败: " & errMsg
end try
end repeat
on error errMsg
display dialog "无法读取文件: " & errMsg
end try
最终结果:在finder中显示应用的备注,并且可以在spotlight中按照你的备注词搜索需要的应用
在文件中就可以直接把comment字段显示出来,方便查看;
在spotlight快捷搜索时,可以直接输入关键词 kind:app来快速找到这类应用
猜你喜欢
- 2024-11-24 这是我见过的最复杂的发版流程,你们那里怎么管理发版部署的呢?
- 2024-11-24 如何做一名出色的初级开发?
- 2024-11-24 99%的程序员都在用Lombok,原理竟然这么简单?
- 2024-11-24 2.8 git版本管理3 怎么用sourceTree新增分支和修改后提交
- 2024-11-24 关于Sourcetree 关联gitee的操作
- 2024-11-24 4款代码管理工具 和 12款GIT GUI软件
- 2024-11-24 VS Code使用Git可视化管理源代码详细教程
- 2024-11-24 深入浅出全栈工程师: 搭建OSX开发环境
- 2024-11-24 GitHub:图形化交互让你轻松管理代码「图解」
- 2024-11-24 程序员:18 个提高生产力的开发者工具,值得收藏
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)