在糾結(jié)這一篇到底要不要發(fā)赊舶,不過(guò)既然是一個(gè)系列的,還是發(fā)出來(lái)吧赶诊。
本篇有很多案例是從別的地址copy的笼平,下面會(huì)有說(shuō)明。如果作者有異議請(qǐng)與我聯(lián)系舔痪。
參考地址http://blog.csdn.net/yang3wei/article/details/7964226
1.使用AppleScript中的對(duì)話(huà)框
這種對(duì)話(huà)框很難符合現(xiàn)在用戶(hù)的審美要求寓调,不過(guò)特別方便。如果你不打算大規(guī)模推廣你的腳本辙喂,而且不是處女座的話(huà)捶牢,也能夠忍受了吧。
最簡(jiǎn)單的樣式
ps:扁平化才是王道巍耗;看多了現(xiàn)代簡(jiǎn)約明快的作品后秋麸,明顯比過(guò)去厚重古老的風(fēng)格更符合時(shí)代精神歹河。不過(guò)說(shuō)不定哪天新一代復(fù)古潮流興起唠摹,誰(shuí)知道呢?发皿!
使用彈出框有一些要注意的地方:
*1 它可以有多個(gè)按鈕的亲族;
*2 它是有返回值的炒考,返回值是你最終操作的字符串;
*3 它是可以增加輸入框的,而且比你想的簡(jiǎn)單多了霎迫。
setdialogString to"Input a number here"
set returnedString to display dialog dialogString default answer ""
看見(jiàn)了嗎斋枢,你用一個(gè)set語(yǔ)句即可獲得對(duì)話(huà)框的返回值;至于輸入框知给,你加一個(gè)default answer ""搞定瓤帚,你可以在雙引號(hào)內(nèi)顯示預(yù)輸入的內(nèi)容描姚。
set dialogString to "Input a number here"
set returnedString to display dialog dialogString default answer ""
set returnedNumber to the text returned of returnedString
try
set returnedNumber to returnedNumber as number
set calNumber to returnedNumber * 100
display dialog calNumber
on error the error_message number the error_number
display dialog "Error:" & the error_number & " Details:" & the error_message
end try
beep
最后一個(gè)beep就讓你的電腦叫一下。
2.使用mac的郵件系統(tǒng)
很顯然戈次,你要發(fā)郵件的話(huà)轩勘,至少要考慮下面這些變量:收件人,標(biāo)題怯邪,內(nèi)容绊寻,附件等等⌒看到下面的代碼澄步,你差不多應(yīng)該明白了。
--Variables
set recipientName to " 小紅"
set recipientAddress to "xiaohong@163.com"
set theSubject to "AppleScript Automated Email"
set theContent to "This email was created and sent using AppleScript!"
--Mail Tell Block
tell application "Mail"
--Create the message
set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
--Set a recipient
tell theMessage
make new to recipient with properties {name:recipientName, address:recipientAddress}
--Send the Message
send
end tell
end tell
如果你想快速回復(fù)確認(rèn)的內(nèi)容的話(huà)和泌,這個(gè)腳本或許有用驮俗;當(dāng)然,我認(rèn)為它最大的用處應(yīng)該是騷擾別人允跑。
3.讓瀏覽器打開(kāi)網(wǎng)頁(yè)
每天上班的時(shí)候,我肯定會(huì)用到瀏覽器搪柑。休息的時(shí)候會(huì)逛一下CSDN聋丝,現(xiàn)在還有一些不錯(cuò)的搜索引擎可以玩:快搜可以直接Google哦;中國(guó)搜索剛剛上線(xiàn)工碾,有一些不錯(cuò)的內(nèi)容弱睦,支持國(guó)產(chǎn);必應(yīng)的頁(yè)面好看渊额,光放著也是不錯(cuò)的嘛况木。
這里瀏覽器用的是Chrome:
set urlMyBlog to "http://blog.csdn.net/u011238629"
set urlKuaiso to "http://so.chongbuluo.com/"
set urlChinaSearch to "http://www.chinaso.com"
set urlBiying to "https://cn.bing.com"
--使用Chrome瀏覽器
tell application "Google Chrome"
--新建一個(gè)chrome窗口
set window1 to make new window
tell window1
--當(dāng)前標(biāo)簽頁(yè)加載必應(yīng),就是不用百度哈哈
set currTab to active tab of window1
set URL of currTab to urlBiying
--打開(kāi)csdn博客,搜索
make new tab with properties {URL:urlMyBlog}
make new tab with properties {URL:urlChinaSearch}
make new tab with properties {URL:urlKuaiso}
--將焦點(diǎn)由最后一個(gè)打開(kāi)的標(biāo)簽頁(yè)還給首個(gè)標(biāo)簽頁(yè)
set active tab index of window1 to 1
end tell
end tell
4.讓你的電腦說(shuō)話(huà)
這個(gè)技能可以用來(lái)配音的旬迹。
tell current application
say "How are you?" using "Zarvox"
say "Fine,thank you." using "Victoria"
say "Ha Ha"
--嘟嘟響一聲
beep
end tell
5.清理廢紙簍
tell application "Finder"
empty the trash
beep
open the startup disk
end tell
就寫(xiě)到這里吧火惊,上面都是網(wǎng)上很容易搜索到的東西。至于我的目標(biāo)之一是用AppleScript控制Xcode做一些事奔垦,如果有收獲再分享吧屹耐。
今天的代碼排版可能好一些,學(xué)習(xí)了一下Markdown的編輯方式:http://www.reibang.com/p/q81RER