AppleScript预定义变量详解

需积分: 44 37 下载量 193 浏览量 更新于2024-08-08 收藏 2.4MB PDF 举报
"AppleScript 简明基础教程" AppleScript是一种强大的脚本语言,专为苹果 macOS 操作系统设计,允许用户与内置应用程序以及第三方软件进行交互,自动化任务和流程。预定义变量在AppleScript中扮演着重要角色,它们提供了一些预设的值和功能,简化了编程过程。 一、预定义变量 1. `result`:这个变量存储了最近执行的命令的返回结果。如果命令没有返回值,`result` 将设置为一个错误状态。例如,当执行一个计算或查询操作后,你可以通过`result`来获取结果。 2. `it`:这是一个特殊变量,它代表最近被操作的对象。在语句序列中,`it` 可以用来引用前一个命令的输出,方便连续操作。例如,如果你告诉一个文本编辑器选取一段文本,然后使用`it`,则会自动处理之前选取的文本。 3. `me`:此变量表示当前运行的脚本本身。它可以帮助获取脚本的路径或者执行与脚本相关联的操作,比如`path to me`返回脚本所在的完整路径。 4. `tab` 和 `return`:这两个变量分别代表一个制表符和一个换行符,常用于构建格式化的字符串输出。在需要插入分隔符或者新行时,可以直接使用它们,而无需手动输入。 二、AppleScript学习与应用 AppleScript因其易学性和实用性而在 macOS 用户中受到欢迎。通过学习AppleScript,用户可以编写简单的脚本来自动化日常的重复性任务,提高效率,避免手动完成繁琐的操作。例如,你可以创建一个脚本来批量重命名文件、整理邮件,甚至控制多个应用程序之间的数据交换。 三、AppleScript与Automator Automator是苹果提供的一个图形化工作流工具,它允许用户通过拖拽操作构建自动化流程,而AppleScript则是Automator中的一个重要组成部分。在Automator的工作流中,可以插入AppleScript步骤来执行更复杂的逻辑或处理,使自动化程度进一步提升。 四、资源与学习资料 尽管AppleScript的学习资源相对较少,但仍有官方文档《AppleScript Language Guide》以及一些在线社区(如developer.apple.com和macscripter.com)提供帮助。此外,教程作者Nathan分享了他的个人经验,以简洁明了的方式介绍了AppleScript的基础知识和实用技巧,为初学者提供了很好的学习途径。 总结: AppleScript的预定义变量为编写脚本提供了便利,它们简化了代码并增强了脚本的灵活性。通过学习和利用这些变量,用户可以更高效地利用AppleScript实现自动化,提高工作效率。同时,配合Automator这样的工具,自动化能力将进一步增强。对于有兴趣掌握AppleScript的用户,可以通过官方文档和教程作者提供的资源开始学习之旅。

解释:% 'Distance' - Distance measure, in P-dimensional space, that KMEANS % should minimize with respect to. Choices are: % {'sqEuclidean'} - Squared Euclidean distance (the default) % 'cosine' - One minus the cosine of the included angle % between points (treated as vectors). Each % row of X SHOULD be normalized to unit. If % the intial center matrix is provided, it % SHOULD also be normalized. % % 'Start' - Method used to choose initial cluster centroid positions, % sometimes known as "seeds". Choices are: % {'sample'} - Select K observations from X at random (the default) % 'cluster' - Perform preliminary clustering phase on random 10% % subsample of X. This preliminary phase is itself % initialized using 'sample'. An additional parameter % clusterMaxIter can be used to control the maximum % number of iterations in each preliminary clustering % problem. % matrix - A K-by-P matrix of starting locations; or a K-by-1 % indicate vector indicating which K points in X % should be used as the initial center. In this case, % you can pass in [] for K, and KMEANS infers K from % the first dimension of the matrix. % % 'MaxIter' - Maximum number of iterations allowed. Default is 100. % % 'Replicates' - Number of times to repeat the clustering, each with a % new set of initial centroids. Default is 1. If the % initial centroids are provided, the replicate will be % automatically set to be 1. % % 'clusterMaxIter' - Only useful when 'Start' is 'cluster'. Maximum number % of iterations of the preliminary clustering phase. % Default is 10. %

2023-05-18 上传