使用AppleScript实现一个批量添加文件前缀的功能

  AppleScript是Mac系统提供的一个脚本语言,这个脚本语言简单易读,即使不会编程也能够很快的学会使用这种语言, AppleScript可以让我们的日常工作流程化,简化繁琐的固定输入,自动化完成一般的日常工作。

首先是要打开Mac自带的脚本编辑器,直接搜索 Script Editor就能够打开脚本编辑器

下面是源码

 1 property prifix : ""
 2 display dialog "批量添加文件前缀名" default answer prifix buttons {"取消", "确定"} default button "确定" with title "请输入前缀名"
 3 set myResult to the result
 4 if button returned of the myResult = "取消" then
 5     continue quit
 6 end if
 7 set prifix to text returned of myResult
 8 on open frameworkFile
 9     tell application "Finder"
10         set i to 1
11         set maxCount to count of frameworkFile
12         repeat maxCount times
13             set theFile to item i of frameworkFile
14             set name of theFile to (prifix & (name of theFile))
15             set i to i + 1
16         end repeat
17     end tell
18 end open

下面是行号及对应的作用

1:定义一个属性用来储存你要的添加的前缀

2 - 7: 当打开脚本时会弹出文本框用来录入你需要添加的前缀(默认会有上一次的前缀)

8 :让你能够把需要更名的文件拖拽到脚本图标上执行

9 - 17 : 便利所有的文件对象,在它的名字上加上前缀

当你使用脚本的时候需要把它保存为“应用程序” 因为只有这样才能够接受 ON OPEN 事件

还要勾上运行处理程序后保持打开,这样才能愉快的拖文件吗....

然后就没然后了,就是这么简单!

菜鸟一枚,希望多多鼓励!

posted @ 2016-01-04 13:18  SSBun  阅读(950)  评论(0编辑  收藏  举报