1
OSXでPath Finderで選択したファイルの名前を変更するzshスクリプトを作成しています。このスクリプトは、AppleScriptを介して一連のパスを取得します。配列項目は、名前の変更/移動のためにforループで処理されます。スクリプトは、ファイル名にスペースが含まれている場合を除き、作品Bash/ZSH - forループでスペースを含むファイル名を扱う方法([@]を使用)
'/Users/bwitime/Downloads/2017-05-17 at 12.08.jpeg', '/Users/bwitime/Downloads/Raspberry Pi - 5 Book Collection.pdf'
:よう アレー出力が見えます。
read -A myFiles < <(/usr/bin/osascript <<'EOS';
tell application "Path Finder"
set finderSelection to {}
set selectedItems to selection
repeat with theItem in selectedItems
set selFile to quoted form of (get POSIX path of (contents of theItem))
copy selFile to the end of finderSelection
end repeat
end tell
return finderSelection
EOS
)
for i in ${myFiles[@]}
do
FILE=$(echo "$i" | sed 's:,::g' | sed s:"'"::g)
DIR="${FILE:h}"
FILENAME="${FILE:t}"
FOLDERPREFIX="${FILE:h:t}"
mv "$FILE" "$DIR/$FOLDERPREFIX-$FILENAME"
done
$ Iリターンとして: はここにスクリプトだ私はすでにIFS = '\ n' を設定しようとしました
'/Users/bwitime/Downloads/2017-05-17
at
12.08.jpeg',
'/Users/bwitime/Downloads/Raspberry
Pi
5
Book
Collection.pdf'
、ない改行の間には存在しないので、それは動作しません。配列内のファイル。また、二重引用符は効果がありません。
この問題に対処するにはどうすればよいですか?
AppleScriptは配列を返しません。配列の*要素*の単一の文字列表現を返します。 'read'は引用符が構文的であるとは考えません。 – chepner
AppleScriptでもファイルを移動してみませんか? – chepner