繰り返しのファイル圧縮をAutomatorで自動にしたい
繰り返しのファイル圧縮をAutomatorで自動にしたいです
フォルダの中に圧縮したい画像が入っていてフォルダ内の画像を全部選択して圧縮をしたい
フォルダは大量にあります
フォルダではなくフォルダ内の画像を圧縮したいと思ってAutomatorをいじっていましたができません
同じような作業を自動にしてる方がいましたら教えて下さい
よろしくお願いします。
iMac 21.5", macOS 10.15
繰り返しのファイル圧縮をAutomatorで自動にしたいです
フォルダの中に圧縮したい画像が入っていてフォルダ内の画像を全部選択して圧縮をしたい
フォルダは大量にあります
フォルダではなくフォルダ内の画像を圧縮したいと思ってAutomatorをいじっていましたができません
同じような作業を自動にしてる方がいましたら教えて下さい
よろしくお願いします。
iMac 21.5", macOS 10.15
こんなのでいかがでしょう?
-- ---------------------------------------------------------------------------------------
activate me
display dialog "Zipファイルを、デスクトップに作成します。" giving up after 5
delay 3
set selItems to getFinderSelection() of me
if selItems is false then
display alert "ファイルが選択されていません。" as warning
else
repeat with tgtItem in selItems
zipIt(tgtItem) of me
end repeat
end if
--Finderで選択中のフォルダを取得する
on getFinderSelection()
tell application "Finder"
try
set aSel to selection as alias list
on error
set aSel to {}
end try
if aSel is not equal to {} then
return aSel --selectionが存在していた場合
else
return false --なんにも選択されていなかったらfalseを返す
end if
end tell
end getFinderSelection
-- エイリアスを渡すとそのアイテムをZIP圧縮するルーチン
on zipIt(tgtItem)
tell application "Finder"
-- 処理対象の名前を取得
set tgtName to name of tgtItem as Unicode text
set tgtName2 to quoted form of tgtName
-- カレントディレクトリを取得
set tgtParent to parent of tgtItem as alias
set tgtParent to quoted form of POSIX path of tgtParent
set zipName to retFileNameWithoutExt(tgtName) of me & ".zip"
set zipName to quoted form of zipName
end tell
-- フォルダの中身を全て階層的に圧縮
do shell script "cd " & tgtParent & " ; " & "zip -r " & zipName & " " & tgtName2
--デスクトップに移動
set dDir to quoted form of (POSIX path of (path to desktop))
log tgtParent & "->" & dDir
if tgtParent is not equal to dDir then
do shell script "mv -f " & tgtParent & "/" & zipName & " " & dDir
end if
end zipIt
--ファイル名から拡張子を外す
on retFileNameWithoutExt(fileNameStr)
set fLen to length of fileNameStr
set revText to (reverse of (characters of fileNameStr)) as string --逆順テキストを作成
set anOffset to offset of "." in revText
set fRes to text 1 thru (fLen - anOffset) of fileNameStr
return fRes
end retFileNameWithoutExt
-- ---------------------------------------------------------------------------------------
返信ありがとうございます
フォルダにある複数の画像まとめてZIPに圧縮したいと考えています
よろしくお願いします。
こんなのはどうですか?
「画像を圧縮」というのは、フォーマットを変える(例えばBMPからJPEGにとか)ということですか?
それとも一つ一つをZipとかに圧縮するってことですか?
後者はあんまり意味がないと思うけど。
ZIPやdmgに圧縮する方法なら、Apple Scriptで作成して使ってます。
Finderで選択した全ての項目を、一つずつ圧縮するスクリプトです。
ご入用ならお示しします。
繰り返しのファイル圧縮をAutomatorで自動にしたい