(*
★このスクリプトについて
Windowsで文字化けしないzipを作るスクリプト
転載、改造、再配布OK。
★準備
・convmvのインストール
http://www.j3e.de/linux/convmv/
からconvmvをダウンロードして解凍します。
方法1:簡単な方法
解凍したフォルダ内にあるconvmvを
アプリケーションフォルダに移動します。
方法2:ターミナルを使う方法
ターミナルで解凍したフォルダに移動して
$ make
$ sudo make install
のコマンドを実行します。これでインストール完了です。
★使い方
・Finderで変換したいファイルを選択して、このスクリプトを実行します。
OS標準の機能ではスクリプトメニューが便利です。
またこのスクリプトをアプリケーションとして保存するとドロップレットとして使うことが出来ます。
★注意点
ファイル名に含まれる文字によっては文字化けしないzipが作れないかもしれません。
*)
(*
原案:
ID:76G3QLdG0さん
0. convmvをインストール。
1. UFSフォーマットのイメージファイルをディスクユーティリティで作成し、マウント。
2. 圧縮したいものをそのボリュームにコピー
3. メタデータの「._*」ファイルを削除(お好みで)
3. convmv -r -f utf8 -t sjis * という感じでファイル・フォルダ名を変換
4. zip -r hoge.zip * などで圧縮。
ID:MUvS6O+B0さん
convmv --listにsjisが入ってないから、
cp932を使ったほうが安全かも。
> convmv -r -f utf8 -t cp932 *
*)
(*
更新履歴:
2007-09-10 初公開
2007-09-11 同名のzipファイルがある場合ユニークな名前にして上書きされないようにした
ファイルサイズを計算してディスクイメージを作るようにした
圧縮するファイル名によってはzipファイルの名前を作成する時にエラーが出ていたのを修正
*)
-----
on run
tell application "Finder"
set theFiles to selection
if (count theFiles) > 0 then
set path1 to item 1 of theFiles as Unicode text
set path2 to path to me as Unicode text
--display alert path1 & return & path2
if path1 is path2 then
beep
display dialog "アプケーション自身は圧縮できません" buttons {"OK"} default button 1
return
end if
my makeSjisZipFile(theFiles)
else
beep
display dialog "処理対象のファイルが無いです。" buttons {"OK"} default button 1
return
end if
end tell
end run
on open (inFiles)
my makeSjisZipFile(inFiles)
end open
on makeSjisZipFile(inFiles)
set convmvPath to my convmvPath()
if convmvPath is "" then
beep
display dialog "convmvが見つからないので処理を停止します。" & return & "このスクリプトをスクリプトエディタで開くと説明が書いてあります。" buttons {"OK"} default button 1
return
end if
set theFileCount to count inFiles
--zipファイル名作成
tell application "Finder"
set zipPathWithoutExt to (item 1 of inFiles as alias) as string
if theFileCount is 1 then
if zipPathWithoutExt ends with ":" then
set zipPathWithoutExt to text 1 thru -2 of zipPathWithoutExt as Unicode text
end if
else
if zipPathWithoutExt ends with ":" then
set zipPathWithoutExt to text 1 thru -2 of zipPathWithoutExt as Unicode text
end if
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":" as Unicode text}
set theList to text items of zipPathWithoutExt
set folderPath to (items 1 thru -2 of theList) as text
set AppleScript's text item delimiters to oldDelimiters
set zipPathWithoutExt to folderPath & ":archive"
end if
end tell
set zipPath to makeUniqueName(zipPathWithoutExt, ".zip")
set allFileSize to 1024 * 12 --よくわからんがシステム領域やファイル名とかの保存分を考慮して余裕を持たせておく。
if theFileCount is 0 then
beep
display dialog "処理対象のファイルが無いです。" buttons {"OK"} default button 1
return
else
--ファイルの合計サイズを計算
repeat with theFile in inFiles
tell application "Finder"
set theName to name of theFile
set theAlias to theFile as alias
set theAliasPath to theAlias as string
set theFilePath to ヌclass psxpネ of theAlias as string
set theSize to ヌevent sysoexecネ "du -sk " & ヌclass strqネ of theFilePath & " | perl -ne 'm/^([0-9]+)/; print $1;'"ア
set allFileSize to allFileSize + theSize + 16 --念のため多めに増やしてみる
if theFilePath ends with "/" then
set allFileSize to allFileSize + 256 --フォルダだとさらに多めに増やしてみる
end if
end tell
end repeat
end if
set theDmgName to "sjisZip_" & (ヌevent sysoexecネ "date '+%m%d_%H%M%S'") & ".sparseimage"
set theDmgPath to ヌclass psxpネ of ((path to temporary items folder as Unicode text) & theDmgName)
-- disk imageを作る
ヌevent sysoexecネ "hdiutil create -fs UFS -size " & allFileSize & "k -volname " & ヌclass strqネ of theDmgName & " " & ヌclass strqネ of theDmgPath -- -type SPARSE
--マウント。アンマウント用にディスク情報を保存しておく
set devName to ヌevent sysoexecネ "hdiutil mount " & ヌclass strqネ of theDmgPath & " | perl -ne 'print $1 if m!^([/a-zA-Z0-9]+).*" & theDmgName & "!'"
set dmgVolumePath to "/Volumes/" & theDmgName
set theIndex to 1
try
repeat with theFile in inFiles
tell application "Finder"
set theName to name of theFile
set theAlias to theFile as alias
set theAliasPath to theAlias as string
if theAliasPath ends with ":" then
--フォルダ
set theFilePath to ヌclass psxpネ of theAlias as string
ヌevent sysoexecネ "ditto --norsrc " & ヌclass strqネ of theFilePath & " " & ヌclass strqネ of dmgVolumePath & "/" & theName
--.DS_Store削除 -- ディスクに対してやるとtrashフォルダでエラーが出たので個別にやる
ヌevent sysoexecネ "cd " & ヌclass strqネ of dmgVolumePath & "/" & theName & "; find . -name '.DS_Store' -delete"
else
set theFilePath to ヌclass psxpネ of theAlias as string
ヌevent sysoexecネ "ditto --norsrc " & ヌclass strqネ of theFilePath & " " & ヌclass strqネ of dmgVolumePath
end if
end tell
end repeat
on error msg
display dialog "ディスクイメージへのファイルのコピー中にエラーが起きたので処理を中止します。" & return & msg buttons {"OK"} default button 1
return
end try
ヌevent sysoexecネ "cd " & ヌclass strqネ of dmgVolumePath & "; " & convmvPath & " -r -f utf8 -t cp932 * --notest;" --convmv
ヌevent sysoexecネ "cd " & ヌclass strqネ of dmgVolumePath & "; zip -r " & ヌclass strqネ of ヌclass psxpネ of zipPath & " *" --zip作成
ヌevent sysoexecネ "hdiutil detach " & ヌclass strqネ of devName --アンマウント
ヌevent sysoexecネ "rm " & ヌclass strqネ of theDmgPath --dmg削除
tell application "Finder"
set selection to zipPath as alias
beep
activate
display dialog "zipの作成が終わりました" buttons {"OK"} default button 1
end tell
end makeSjisZipFile
on convmvPath()
try
ヌevent sysoexecネ "ls /Applications/convmv"
return "/Applications/convmv"
end try
try
ヌevent sysoexecネ "ls /usr/local/bin/convmv"
return "/usr/local/bin/convmv"
end try
return ""
end convmvPath
on makeUniqueName(inBaseHFSPathName, inExtention) --
tell application "Finder"
try
set theIndex to 1
set theTestName to inBaseHFSPathName & inExtention
repeat
theTestName as alias -- ファイルが無ければここでエラーになるのでループ終了
set theTestName to inBaseHFSPathName & "_" & theIndex & inExtention
set theIndex to theIndex + 1
end repeat
end try
end tell
return theTestName
end makeUniqueName

0 件のコメント:
コメントを投稿