Mac 脚本编辑器(AppleScript)如何使用录制功能
程序员文章站
2024-01-16 21:41:22
...
1、打开脚本编辑器,点击启动台 -> 其他 -> 脚本编辑器,或直接浏览器中输入applescript://,然后按回车键。
2、新建文稿,按Command+s组合键进行保存,选择保存位置和文件格式,格式选择[脚本]。
3、点击录制按钮,如图
4、新建一个Finder窗口,把跟Finder相关的所有操作都做一遍。如打开文稿,打开图片,打开文件夹,拖拽窗口大小,设置文件显示方式(图标、列表、分栏等)。
5、会发现脚本文稿中多了一些代码,这就是录制得到的代码。点按停止按钮,停止录制。
6、目前发现只能对Finder进行录制操作,其他软件应该是不可以。
7、这个功能可以帮助更好的理解脚本编辑器能做的事,以及脚本编辑器的一些语法。
8、示例录制得到的代码如下:
tell application "Finder"
activate
close Finder window id 963
make new Finder window
set target of Finder window 1 to folder "Desktop" of folder "userName" of folder "Users" of startup disk
set target of Finder window 1 to folder "Documents" of folder "userName" of folder "Users" of startup disk
set target of Finder window 1 to folder "Downloads" of folder "userName" of folder "Users" of startup disk
set target of Finder window 1 to folder "Documents" of folder "userName" of folder "Users" of startup disk
set target of Finder window 1 to folder "xxx" of folder "xxx" of folder "Documents" of folder "userName" of folder "Users" of startup disk
set current view of Finder window 1 to icon view
set current view of Finder window 1 to list view
set current view of Finder window 1 to column view
set current view of Finder window 1 to flow view
set current view of Finder window 1 to column view
open document file "xxx.txt" of folder "xxx" of folder "xxx" of folder "Documents" of folder "userName" of folder "Users" of startup disk
close Finder window id 1118
end tell