在mac怎么写脚本

1.如何写一个脚本操作MAC地址echo "00:00:27:1d:01:ff"|awk -F":" 'BEGIN{hex=256}function dtoh(i){return strtonum("0x"i)}{mac=dtoh($1)*hex^5+dtoh($2)*hex^4+dtoh($3)*hex^3+dtoh($4)*hex^2+dtoh($5)*hex+dtoh($6);mac++;printf("%02x:%02x:%02x:%02x:%02x:%02x\n",int(mac/hex^5),int(mac%hex^5/hex^4),int(mac%hex^5%hex^4/hex^3),int(mac%hex^5%hex^4%hex^3/hex^2),int(mac%hex^5%hex^4%hex^3%hex^2/hex),mac%hex^5%hex^4%hex^3%hex^2%hex)}'
00:00:27:1d:02:00
2.如何写一个脚本操作MAC地址echo "00:00:27:1d:01:ff"|awk -F":" 'BEGIN{hex=256}function dtoh(i){return strtonum("0x"i)}{mac=dtoh($1)*hex^5+dtoh($2)*hex^4+dtoh($3)*hex^3+dtoh($4)*hex^2+dtoh($5)*hex+dtoh($6);mac++;printf("%02x:%02x:%02x:%02x:%02x:%02x\n",int(mac/hex^5),int(mac%hex^5/hex^4),int(mac%hex^5%hex^4/hex^3),int(mac%hex^5%hex^4%hex^3/hex^2),int(mac%hex^5%hex^4%hex^3%hex^2/hex),mac%hex^5%hex^4%hex^3%hex^2%hex)}'
00:00:27:1d:02:00
3.如何在mac程序代码中调用AppleScript脚本关于AppleScript说到AppleScript , 可能涉及到三个含义:1.AppleScript语言:就是苹果脚本的语言 , 用来编写运行于Mac系统的脚本 。
2.AppleScript脚本:就是使用AppleScript语言编写的一系列指令 。以后简称脚本 。
3.AppleScript脚本解释程序:用于解释和执行AppleScript脚本中指令的程序 。是Mac系统的原生程序和重要组成部分 。
下面简称AppleScript脚本程序 。AppleScript Editor要编写AppleScript脚本 , 当然就需要编辑工具了 , 首先打开AppleScript编辑器:貌似可以使用Xcode编写Cocoa - AppleScript Application , 这个暂时还没尝试 。
我们先从AppleScript编辑器开始 。界面很简单 , 主要分为工具栏、编辑区和运行结果区 。
编辑区用来编写脚本 , 工具栏用来编译和运行脚本等 , 运行结果区呈现运行结果 , 这个不用多说了吧 。say和beep首先来玩两件很好玩的事:让Mac发音和说话 。
在编辑区输入以下脚本:view sourceprint?1.say "How are you?" using "Zarvox"2.say "Fine, thank you." using "Victoria"3.say "Ha Ha"4.beep点击工具栏的编译(或Command + K) , 可以看到脚本变了颜色 , 具体颜色的含义 , 可以在偏好设置中查看并设置:接着点击运行(Command + R运行 , Command + .停止运行) 。可以看到运行结果区的回复栏中的显示如下:更加好玩的是Mac系统在自然自语了 , 还有最后的一声咚 。
下面来解释下脚本和运行结果的意思:view sourceprint?1.say "说话的内容" using "指定人的嗓音"这句脚本的意思就是让Mac系统按照指定人的嗓音说出我们指定的说话内容 。当然using " 。
"是可以缺省的 。view sourceprint?1.beep 发声次数这句脚本的意思是让Mac系统发出咚的声音 , 发声次数决定了咚出现的次数 , 例如beep 2那么Mac会咚两次 。
【在mac怎么写脚本】发声次数缺省为1 。在运行时回复输出的意思是:tell表明将以上say和beep的任务交付给current application去完成 , 也就是AppleScript脚本程序 。
tell模块同样道理 , 我们可以用tell模块将特定的任务交付给Mac中特定的程序去执行 。tell模块的语法为:view sourceprint?1.tell application "Application Name"2.do your job here3.end tell例如我们想让Finder程序清空垃圾篓然后打开磁盘 , 可以这样写:view sourceprint?1.tell application "Finder"2.empty the trash3.beep4.open the startup disk5.end tell注意"Finder"的双引号必不可少 。
回复输出为:view sourceprint?01.tell application "Finder"02.empty trash03.--> current application04.--> error number 005.beep06.--> error number -1000407.end tell08.tell current application09.beep10.end tell11.tell application "Finder"12.open startup disk13.end tell可以看到empty the trash任务是交给Finder程序去完成的 , 而beep任务是交给current application程序去完成 , 接下来的open the startup disk任务还是交回给Finder程序完成 。在tell模块中的任意位置可以插入beep,say等由current application程序解释执行的语句 。