1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

日本語のファイル名

Last updated at Posted at 2022-08-24

mpg123でネットラジオもいいですが、ローカルのファイルの再生も試してみました。

iBook DualUSB Mac OS X 10.4のiTunesで取り込んだCDデータがあるのですが、m4aなのでmp3に変換します。

iTunesで変換設定を変えると、すでに取り込んである、m4aからmp3が作れました。CDの取り込みと同じ設定なので、分かりにくかったです。

実行してみると、さすがにPowerPC G3だけあって、結構時間かかりました。また取り込んであるものを、再変換すると二重にiTunesに登録されてしまうので、後で整理が必要です。

変換されファイルをUSBメモリにコピーします。USB 1.0なのでこれまた遅いです。

USBメモリをFreeBSDでマウントしてみます。

# mount -t msdos -r /dev/da0s1 /mnt

マウントされたディレクトリを見ると日本語が文字化けしてアクセスできません。FreeBSDではiconvをカーネルに入れると日本語のディレクトリ名やファイル名も処理できるみたいですが、そんな余裕はありません。

しかたがないのでAppleScriptでファイル名をトラック番号だけにするスクリプトを書いてみました。

on open theDroppedItems
	repeat with a from 1 to count of theDroppedItems
		set theCurrentItem to item a of theDroppedItems
		tell application "Finder"
			set folderContents to every item of theCurrentItem
			repeat with theFile in folderContents
				set oldName to name of theFile
				set newName to my tracknoName(oldName)
				--display dialog newName
				set name of theFile to newName
			end repeat
		end tell
	end repeat
end open

on tracknoName(str)
	set str to str as string
	set sppos to offset in str of " "
	set sppos to sppos - 1
	set tc to characters 1 thru sppos of str as text
	return {tc & ".mp3"} as string
end tracknoName

AppleScriptを書くのは10年ぶりくらいで、いろいろ手抜きしてます。スクリプトはEl Capitanで書きましたが、10.4でも実行できました。

アプリケーションで、保存してそのアイコンにフォルダーをドラッグすると中にあるファイルのファイル名が変更されます。

スクリーンショット 2022-08-24 11.01.34.png

スクリーンショット 2022-08-24 11.01.52.png

フォルダー名も適当にasciiにするとマウントして問題なく開ける様になります。

Ver. 2

AppleScriptでscpしてその時に名前を変えるようにしました。読み込んだフォルダーをドラッグするとコピーされて、元のファイルは変更しません。

on open theDroppedItems
        set mp3Server to "10.0.1.41"
 
        repeat with a from 1 to count of theDroppedItems
                set theCurrentItem to item a of theDroppedItems
                display dialog "dirctory name" default answer "test"
                set dirName to text returned of result
                do shell script ("ssh " & mp3Server & " 'mkdir -p " & dirName & "'")
                tell application "Finder"
                        set folderContents to every item of theCurrentItem
                        set thePath to POSIX path of theCurrentItem
                        repeat with theFile in folderContents
                                set oldName to name of theFile
                                set newName to my tracknoName(oldName)
                                --display dialog thePath & oldName
                                --set name of theFile to newName
                                do shell script ("scp \"" & thePath & oldName & "\" " & mp3Server & ":" & dirName & "/" & newName)
                        end repeat
                end tell
        end repeat
end open

on tracknoName(str)
        set str to str as string
        set sppos to offset in str of " "
        set sppos to sppos - 1
        set tc to characters 1 thru sppos of str as text
        return {tc & ".mp3"} as string
end tracknoName

POSIXのファイル名で使えない/などが入っているとエラーになります。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?