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会咚两次。
发声次数缺省为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程序解释执行的语句。
注意,交付给某个程序执行的语句必须在tell模块之内。错误写法:view sourceprint?1.tell application "Finder"2.empty the trash3.beep4.end tell5.open the startup disk编译时可以看到没有报错,运行起来看看:运行结果区的回复输出如下: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 "AppleScript Editor"12.open startup disk13.--> missing value14.end tell15.结果:16.missing valueboot应该由Finder程序去打开,但是由于超出了tell applicaiton "Finder"模块,所以给语句将交由AppleScript Editor程序解释执行,很可惜,AppleScript编辑器无法打开boot,报错。
AppleScript Editor的小技巧1.使用esc键呼出代码补全菜单在写te时按下esc键,此时出现代码补全菜单:2.在编辑区点击右键(或按住control键再点击左键)呼出上下文菜单在上下文菜单中我们可以将AppleScript语句快速地插入到编辑区中,例如:也可以将一段语句插入到Tell语句块中,方法是先选中这段语句,再插入到Tell Blocks中:3.编辑程序的补全和修正功能你可以输入:view sourceprint?1.tell app "Finder"2.end在编译后将被替换为:view sourceprint?1.tell application "Finder"2.end tell在编写AppleScript脚本时,是不区分大小写的,当然在编译过后也会被替换成正确的大小写形式。这些小技巧都非常有利于快速编写脚本。
保存脚本写好了程序,当然是保存了。可以在菜单中点击文件 —— 存储(或按快捷键Command + S)。
在保存时有多种文件格式:保存为脚本格式如果保存为脚本,那么下次打开文件时还是用AppleScript编辑程序来打开。桌面图标如下:保存为应用程序格式如果保存为应用程序,那么最好保留个脚本的copy,否则将不能用AppleScript Editor来打开编辑。
保存时的对话框如下:如果选中“显示启动屏幕”,那么以后运行程序前会弹出一个对话框提示:如果选中“运行处理程序后保持打开”选项,那么在程序运行完毕后会。
4.如何在mac shell下批处理文本内容
mac终端下运行shell脚本
1、写好自己的 脚本,比如aa.sh
2、打开终端 执行,方法一: 输入命令 ./aa.sh ,
方法二:直接把 aa.sh 拖入到终端里面。
注意事项:
如果 没有成功报出问题::
Permission denied。就是没有权限。
解决办法:
修改该文件aa.sh 的权限 :使用命令:
chmod 777 aa.sh 。
然后再执行 上面第二步的操作 就 OK .