applescript编辑软件的使用


1、让计算机发声。最后发两次“咚”的声音

  1. using为使用哪种朗读的语音,省略using关键字,就是用默认的朗读语音。
  2. beep发出咚咚的声音 beep number
say "Let's study applescript" using "Fred"
beep 2

2、调用Finder程序,去清空回收站里面的垃圾

tell application "Finder"empty the trash
end tell

3、变量赋值

set str to ""
set str2 to "test"
set result to "Nealyang"

4、弹框提示消息

  1. display dialog显示弹框
set stringToBeDispalyed to "hi there"
display dialog "stringToBeDispalyed"
display dialog stringToBeDispalyed

5、字符串拼接

  1. 使用&拼接字符串
set nameOfActress to "Neal is "
set actressRating to " very pretty"
set resultingString to nameOfActress & actressRating
display dialog resultingString

6、类型转换

  set strToNumber to "16" as numberset numToStr to 12 as string

7、获取字符串长度

set theLength to the length of "Neal"

8、弱类型语言数组赋值

set exampleList to {1, 2, 3, "hahah", 9}
set addToBegin to {"winter"}
set addToEnd to {"summer", "autumn"}
set currentList to {"spring"}
set modifiedList to addToBegin & currentList & addToEnd

9、取值

  1. 最左边的index是1
set testList to {"Neal", "haha"}
set item 2 of testList to "yang"
get testList
set the second item of testList to "yang"
set the 2nd item of testList to "yang"
  1. 获取最后一个值
set myList to {"neal", "haha"}
set valueOfLastItem to item -1 of myList
set myList to {"a", "b", "c", "d", "e", "f"}
set shortList to items 2 through 5 of myList

10、reverse取反

set reversedList to reverse of {2, 3, 4, 6, 7}

11、获取数组长度

  1. the length of 和 the count of 效果是一样的
set theListLength to the length of {"ds", 1, 2, 3}
set theListLength to the count of {"ds", 1, 2, 3}

12、随机取值

  1. 随机返回列表中的任一元素
set x to some item of {1, 2, 3, 4, 5, 7, 7, 6, 5}

13、条件语句

set ageEntered to 73
set myAge to 24
if ageEntered is myAge thendisplay dialog "You are as old as I am "beep
end if
say "this sentence is spoken anyway"

14、路径、文件夹和应用程序

set thePath to alias "Macintosh HD:Users:zhouwei:Documents:google"
tell application "Finder"open folder thePath
end tell
  1. 列出所选文件夹中所有的文件夹名称
#set thePath to alias "Macintosh HD:Users:xx:Documents:google"
set folderSelected to choose folder "Select a folder"
tell application "Finder"set listOfFolders to every folder of folderSelected
end tell
set theList to {}
repeat with aFolder in listOfFoldersset temp to the name of aFolderset theList to theList & temp
end repeat

15、带返回值的调用

(*带返回值的函数调用*)
on circleArea(radius)set area to pi * (radius ^ 2)return area
end circleArea
set anArea to circleArea(10)

16、完整发送邮件

(*发送邮件*)
set recipientName to "小红"
set recipientAddress to "xxx@qq.com"
set theSubject to "AppleScript Automated Email"
set theContent to "This email was created and sent using AppleScript!"
tell application "Mail"--创建消息set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}--设置接收信息tell theMessagemake new to recipient with properties {name:recipientName, address:recipientAddress}--发送邮件sendend tell
end tell

17、读写文件

set myFile to alias "Macintosh HD:Users:xiaxuqiang:Desktop:example.txt"
read myFile
set aFile to alias "Macintosh HD:Users:xiaxuqiang:Desktop:example.txt"
set fp to open for access aFile with write permission
write "AppleScript写入文本" to fp
close access fp

18、打印提示

  1. javascript
tell application "Finder"tell me to log "My log entry."
end tell
  1. javascript
console.log("dd");

19、OC桥接大小写转换

use framework "Foundation"
on changeCaseOfText(theText, theCase)set theText to stringWithString_(theText) of NSString of current applicationif theCase contains "lower" thenset theNewText to lowercaseString() of theTextelse if theCase contains "upper" thenset theNewText to uppercaseString() of theTextelseset theNewText to capitalizedString() of theTextend ifreturn (theNewText as string)
end changeCaseOfText
changeCaseOfText("hello", "upper")

20、创建plist文件

(*创建plist文件*)
tell application "System Events"set theParentDictionary to make new property list item with properties {kind:record}set thePropertyListFilePath to "/Users/zhouwei/Desktop/applescript/Example.plist"set thePropertyListFile to make new property list file with properties {contents:theParentDictionary, name:thePropertyListFilePath}-- 第一种方式tell property list items of thePropertyListFile--添加boolean keymake new property list item at end with properties {kind:boolean, name:"booleanKey", value:true}--添加date keymake new property list item at end with properties {kind:date, name:"dateKey", value:current date}--添加list keymake new property list item at end with properties {kind:list, name:"listKey"}--添加number keymake new property list item at end with properties {kind:number, name:"numberKey", value:5}--添加record/dictionary keymake new property list item at end with properties {kind:record, name:"recordKey"}--添加string keymake new property list item at end with properties {kind:string, name:"stringKey", value:"string value"}end tell-- 第二种方式tell property list file thePropertyListFilePath-- 更新值set value of property list item "stringKey" to "new string value"-- 添加值make new property list item at end with properties {kind:string, name:"stringKey2", value:"string value"}end tellend tell

Mac 脚本之applescript相关推荐

  1. Mac(一):Mac脚本编辑器 - AppleScript实现打开终端并执行打开Android模拟器的命令

    废话不多说,直接上才艺 tell application "iTerm"activatecreate window with default profile command &qu ...

  2. 对未标记为可安全执行的脚本_Script Debugger for Mac(脚本调试软件)

    你是否需要一款可以轻松编译AppleScript的工具吗?来试试Script Debugger for Mac吧!Script Debugger Mac版是一款运行在mac平台的调试软件.Script ...

  3. Mac下使用AppleScript批量删除短信

    在https://www.jianshu.com/p/bae74f9eb8e2基础上修改,并参考了https://juejin.cn/post/6850418120416591885的获取鼠标方法. ...

  4. mac 中使用 AppleScript 来发送 iMessage

    本文只是提供方法,造成后果概不负责 收到iMessage广告是不是很烦?这个方法本身本身是一位网友想出来对付iMessage广告的 不过苹果iMessage也存在一个不小的漏洞,那就是如果你狂发iMe ...

  5. mac上用Automator编写自动脚本

    序 变量使用 从下拉列表直接选择变量 将变量拖进区域 输入变量名弹出提示回车选择 脚本 脚本使用 脚本参数传递 变量值传递到脚本 脚本结果设置到变量中 键盘录制鼠标录制 键盘操作 普通字符 特殊字符 ...

  6. Mac 自动化自动操作工作流程(AppleScript)完成日常软件文件网页一键打开

    每天上班都要打开相同的软件.文件.网页,很烦? 每天下班都要关闭相同的软件.文件.网页,很烦? 试试Mac系统自带的脚本AppleScript,一键上班,一键下班. 1.打开脚本编辑器(AppleSc ...

  7. AE对口型动画脚本插件Lipsyncr Mac

    AE软件中如何快速制作高质量的口型动画?Lipsyncr是一款非常不错的基于viseme自动高品质口部动画脚本插件,拥有三种不同viseme映射:4个插图(低质量),7个插图(中等品质),10个插图( ...

  8. 三维卷轴扭曲变形照片墙AE脚本:Transformer 2 mac版

    AEscripts Transformer 2 for Mac是AEscripts系列中蛮受欢迎的一款三维卷轴扭曲变形照片墙AE脚本,ae脚本transformer支持安装在After Effect ...

  9. xcode 及 MAC 常用快捷键

    郝萌主倾心贡献,尊重作者的劳动成果,请勿转载. 如果文章对您有所帮助,欢迎给作者捐赠,支持郝萌主,捐赠数额随意,重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X×××:点我传送 黑苹果键盘对应 ...

最新文章

  1. 树莓派 自动设置分辨率
  2. html5拍照上传 java_如何使用HTML5实现拍照上传应用
  3. [TCP/IP] TCP第三次握手失败怎么办
  4. 浏览器打开位置服务器,如何启动http服务器,然后打开web浏览器?
  5. 如何通过js文件的名称,反查出这个js文件所在project的artifact id和group id
  6. HDU - 1723 - Distribute Message
  7. CSS自定义消息提示
  8. 百度自动推送html5,百度暂停 JS 代码自动推送功能,代码是否需要删除?
  9. ubuntu14.04升级以及gitlab升级
  10. 倍增LCA(bzoj 3732: Network)
  11. 二十三种设计模式[4] - 原型模式(Prototype Pattern)
  12. 【读书笔记《Android游戏编程之从零开始》】9.游戏开发基础(如何快速的进入 Android 游戏开发)
  13. j2me模拟器java游戏存档修改_单机游戏存档修改
  14. 计算机硬件或网络连接失败,Win10系统出现45错误代码:硬件设备未连接到计算机...
  15. 高等数学:第七章 空间解析几何(1)空间解析几何与向量代数
  16. dsp 28377 +RX-8025T 实现RTC功能
  17. Python读取CSV文件,并进行数据可视化绘图
  18. 2020书单、影单、电视剧
  19. 应用程序未安装,已安装了存在签名冲突的同名数据包
  20. https://acm.ecnu.edu.cn(2018 11 16)

热门文章

  1. 外汇术语和缩略语解释
  2. leetcode 545. Boundary of Binary Tree
  3. 新手机为什么一注册陌陌就封解析硬改软改
  4. 根据身份证获取出生日期
  5. 编程和乐高机器人的区别
  6. cocos2d-js中使用react进行裁剪Sprit
  7. 树莓派实验室python人脸识别_使用树莓派进行简易人脸识别
  8. 微信小程序转二维码两种方法
  9. iOS swift5 手动导入SnapKit(不用cocoapods)
  10. 边缘计算,是在炒概念吗?