applescript:選取檔案夾製作磁碟映像檔 *.dmg

本區專門提供 Mac OS X 使用者交換使用心得

版主: ross_ttbryanchangdigdogchester

回覆文章
內容
發表人
留言五百如一日
文章: 610
註冊時間: 12/25/2001 1:01 am

applescript:選取檔案夾製作磁碟映像檔 *.dmg

#1 文章 »

除磁碟工具程式外,Mac OS X 附有 shell 指令 hdiutil,也可製作磁碟映像檔。

此 [url=applescript://com.apple.scripteditor?action=new&script=set%20theFolder%20to%20choose%20folder%0Dset%20posixFolder%20to%20quoted%20form%20of%20POSIX%20path%20of%20theFolder%0Dset%20theName%20to%20name%20of%20%28info%20for%20theFolder%29%0Dset%20dstImage%20to%20quoted%20form%20of%20%28%28POSIX%20path%20of%20%28path%20to%20desktop%20folder%29%29%20%26%20theName%20%26%20%22%2Edmg%22%29%0D%0Ddo%20shell%20script%20%22%2Fusr%2Fbin%2Fhdiutil%20create%20%2Dov%20%2Dimagekey%20zlib%2Dlevel%3D9%20%2Dsrcfolder%20%22%20%26%20posixFolder%20%26%20%22%20%2Dvolname%20%22%20%26%20%28quoted%20form%20of%20theName%29%20%26%20space%20%26%20dstImage%0D%0Dsay%20%22Image%20is%20ready%22]applescript[/url] 會彈出視窗供用者選擇檔案夾,並製成同名的 *.dmg 於桌面上。

代碼: 選擇全部

set theFolder to choose folder
set posixFolder to quoted form of POSIX path of theFolder
set theName to name of (info for theFolder)
set dstImage to quoted form of ((POSIX path of (path to desktop folder)) & theName & ".dmg")

do shell script "/usr/bin/hdiutil create -ov -imagekey zlib-level=9 -srcfolder " & posixFolder & " -volname " & (quoted form of theName) & space & dstImage

say "Image is ready"
回覆文章